java - my app text is overlapping to going into a corner -
this question has answer here:
i started coding , wanted make app tells percentage of number ui keeps overlapping each other please me solve because first app , don't want first app made fail
this looks in android studio
and looks in emulator
package com.example.abhay.mathsucks; import android.os.bundle; import android.support.design.widget.floatingactionbutton; import android.support.design.widget.snackbar; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.toolbar; import android.view.view; import android.view.menu; import android.view.menuitem; import android.widget.button; import android.widget.edittext; import android.widget.textview; public class mainactivity extends appcompatactivity { textview totaltextview; edittext percentagetxt; edittext numbertxt; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); totaltextview = (textview) findviewbyid(r.id.totaltextview); percentagetxt = (edittext) findviewbyid(r.id.percentagetxt); numbertxt = (edittext) findviewbyid(r.id.numbertxt); button calcbtn = (button) findviewbyid(r. id.calcbtn); calcbtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { float percentage = float.parsefloat(percentagetxt.gettext().tostring()); float dec = percentage / 100; float total = dec * float.parsefloat(numbertxt.gettext().tostring()); totaltextview.settext(float.tostring(total)); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } }
this mainactivity.java file
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.example.abhay.mathsucks.mainactivity" tools:showin="@layout/activity_main"> <textview android:id="@+id/totaltextview" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginbottom="443dp" android:paddingtop="10dp" android:text="0" android:textalignment="center" android:textappearance="@android:style/textappearance.material.large" android:textsize="40sp" app:layout_constraintbottom_tobottomof="parent" app:layout_constrainthorizontal_bias="0.0" app:layout_constraintleft_toleftof="parent" app:layout_constraintright_torightof="parent" /> <textview android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="%" android:textalignment="center" android:textsize="20sp" tools:layout_editor_absolutex="353dp" tools:layout_editor_absolutey="206dp" /> <textview android:id="@+id/textview2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingtop="10dp" android:text="what is" android:textalignment="center" android:textsize="20sp" android:visibility="visible" tools:layout_editor_absolutex="147dp" tools:layout_editor_absolutey="104dp" /> <edittext android:id="@+id/numbertxt" android:layout_width="368dp" android:layout_height="wrap_content" android:ems="10" android:hint="enter number" android:inputtype="numberdecimal" android:paddingtop="10dp" android:textalignment="center" android:textsize="18sp" tools:layout_editor_absolutex="-4dp" tools:layout_editor_absolutey="370dp" /> <edittext android:id="@+id/percentagetxt" android:layout_width="337dp" android:layout_height="wrap_content" android:ems="10" android:hint="enter percentage" android:inputtype="numberdecimal" android:textalignment="center" android:visibility="visible" tools:layout_editor_absolutex="12dp" tools:layout_editor_absolutey="170dp" /> <textview android:id="@+id/textview3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingtop="10dp" android:text="of" android:textalignment="center" android:textsize="20sp" android:visibility="visible" tools:layout_editor_absolutex="170dp" tools:layout_editor_absolutey="272dp" /> <button android:id="@+id/calcbtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#f92b2b" android:paddingtop="10dp" android:text="calculate" android:textcolor="@android:color/background_light" android:textcolorlink="@android:color/background_light" android:textsize="10sp" tools:layout_editor_absolutex="136dp" tools:layout_editor_absolutey="447dp" /> </android.support.constraint.constraintlayout>
content_main.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.coordinatorlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.abhay.mathsucks.mainactivity"> <android.support.design.widget.appbarlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/apptheme.appbaroverlay"> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" android:background="#f92b2b" app:popuptheme="@style/apptheme.popupoverlay" /> </android.support.design.widget.appbarlayout> <include android:id="@+id/back" layout="@layout/content_main" android:visibility="visible" tools:ignore="includelayoutparam" /> </android.support.design.widget.coordinatorlayout>
activity_main.xml
i think messed constraint-layout... may 1 you
<relativelayout android:layout_width="match_parent" android:layout_height="match_parent" > <linearlayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:text="0" android:layout_margintop="10dp" android:textsize="20dp" android:textcolor="#000" android:gravity="center"/> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:text="what is" android:layout_margintop="30dp" android:textsize="20dp" android:gravity="center"/> <linearlayout android:weightsum="2" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <edittext android:layout_weight="1.5" android:layout_marginright="20dp" android:layout_marginleft="20dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="enter percentage" android:layout_margintop="30dp" android:textsize="20dp" android:maxlength="3" android:inputtype="number" android:gravity="center"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="%" android:layout_margintop="30dp" android:textsize="20dp" android:layout_weight="0.5" android:gravity="center"/> </linearlayout> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:text="of" android:layout_margintop="50dp" android:textsize="20dp" android:gravity="center"/> <edittext android:layout_weight="1.5" android:layout_marginright="20dp" android:layout_marginleft="20dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="enter number" android:layout_margintop="30dp" android:textsize="20dp" android:inputtype="number" android:gravity="center"/> </linearlayout> <button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="calculate" android:layout_alignparentbottom="true"/>
wiki
Comments
Post a Comment