Android: auto-resize for each device - java

I've create a very simple app and i download it in 15 different devices. For some of them the layout have no resize problem and appear like this:
Layout that should be in all layouts
But when i installed the app in a Sansung Galaxy Neo Plus and in the tablet Archos 101 Copper the items' layout were not in the position that i want. In the tablet are up of the background different color view and in the Galaxy Neo Plus are like this:
Layout in the Galaxy Neo Plus
To auto-resize, in the activities xml, i used thse codes:
android:layout_marginTop="125dp"
android:layout_marginBottom="15dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
to set the buttons' margin from top/bottom/left/right
android:textSize="30dp"
to set the size of buttons' text
The layout code is this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Al meglio di:"
android:textSize="22dp"
android:id="#+id/almegliodi"
android:layout_alignParentTop="true"
android:layout_marginTop="220dp"
android:layout_centerHorizontal="true"
android:typeface="serif"
android:textStyle="bold|italic"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" UNO "
android:textStyle="bold"
android:textSize="35dp"
android:textColor="#android:color/white"
android:id="#+id/uno"
android:background="#android:drawable/dialog_holo_dark_frame"
android:onClick="uno"
android:layout_below="#+id/almegliodi"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" TRE "
android:textStyle="bold"
android:textSize="35dp"
android:textColor="#android:color/white"
android:id="#+id/tre"
android:background="#android:drawable/dialog_holo_dark_frame"
android:onClick="tre"
android:layout_centerHorizontal="true"
android:layout_below="#+id/uno"
android:layout_marginTop="30dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" CINQUE "
android:textStyle="bold"
android:textSize="35dp"
android:textColor="#android:color/white"
android:id="#+id/cinque"
android:background="#android:drawable/dialog_holo_dark_frame"
android:onClick="cinque"
android:layout_centerHorizontal="true"
android:layout_below="#+id/tre"
android:layout_marginTop="30dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ESCI"
android:textStyle="bold"
android:textSize="30dp"
android:id="#+id/esci"
android:background="#android:color/transparent"
android:layout_marginBottom="7dp"
android:layout_marginLeft="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:onClick="esci"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="INDIETRO"
android:textStyle="bold"
android:textSize="30dp"
android:textColor="#android:color/white"
android:id="#+id/indietro"
android:background="#android:color/transparent"
android:onClick="indietro"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_alignTop="#+id/esci"
android:layout_marginRight="30dp"
android:layout_marginBottom="7dp"
/>
</RelativeLayout
I searched on google but i found that use the 'dp' is the best way to auto-resize margin and text in all device.
What are my mistakes? What i have to do to solve the compatibility?
Thank you

Here is an example how your layout could look like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#005"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
android:src="#android:drawable/btn_star_big_on"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_margin="24dp"
android:layout_weight="1"
android:background="#cfff"
android:gravity="center"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"/>
<android.support.v4.widget.Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"/>
</LinearLayout>
</LinearLayout>
You should of cause use #string/ for each button to make your app translatable, but that basic layout should give you the right idea how to make a layout which scales correctly.
Basically I use some linear layouts which just say how the views should been arranged (horizontal or vertical). Then I told the view which contains the three main buttons that its height should be zero (just for performance) and the most important part that the layout weight is 1 (android:layout_weight="1") that tells the system to split up the open space to all views with a weight attribute. So this one will fill your display as far as possible. The other views will still been rendered as you want in my case wrap_content.

Related

why doesn't my banner appear in Linearlayout?

I am using relative layout in linear layout.My banner appears on the design screen, but no ads appear when I run my application.I looked at many examples but I could not find.My application was horizontal before now I'm designing vertically.Previously I was using Relativelayout then my banner was working.Here my code;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".MainActivity"
android:orientation="vertical"
android:weightSum="12"
android:background="#fffdd0">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="2">
<RelativeLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true">
<Button
android:id="#+id/btn_double"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentStart="true"
android:background="#drawable/xx"
android:layout_marginTop="15dp"/>
<Button
android:id="#+id/btn_yariyariya"
android:layout_width="47dp"
android:layout_height="47dp"
android:background="#drawable/fiftyfifty"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"/>
<Button
android:id="#+id/btn_skip"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentEnd="true"
android:background="#drawable/skip"
android:layout_marginTop="15dp"/>
<TextView
android:id="#+id/tv_countdown2x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13sp"
android:layout_alignParentStart="true"
android:textColor="#color/colorPrimary"
android:layout_below="#+id/btn_double" />
<TextView
android:id="#+id/tv_countdown50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_centerHorizontal="true"
android:textColor="#color/colorPrimary"
android:layout_below="#+id/btn_yariyariya"/>
<TextView
android:id="#+id/tv_countdownNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13sp"
android:layout_alignParentEnd="true"
android:textColor="#color/colorPrimary"
android:layout_below="#+id/btn_skip"/>
<TextView
android:id="#+id/tv_countdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="00:30"
android:textSize="30sp"
android:layout_centerHorizontal="true"
android:textColor="#color/colorPrimary"
android:layout_marginTop="85dp" />
<FrameLayout
android:id="#+id/container_pop_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp" />
</RelativeLayout>
<TextView
android:id="#+id/tv_countdown1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:layout_marginStart="40dp"
android:layout_marginTop="60dp"
android:textColor="#color/colorPrimary"/>
<Button
android:id="#+id/btn_kalp1"
android:layout_width="50dp"
android:layout_height="40dp"
android:background="#drawable/kalp"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="15dp"/>
<Button
android:id="#+id/btn_satinal"
android:layout_width="50dp"
android:layout_height="40dp"
android:layout_marginStart="200dp"
android:onClick="satinalMain"
android:background="#drawable/satinal"
android:layout_alignParentEnd="true"
android:layout_marginEnd="30dp"
android:layout_marginTop="15dp"/>
<TextView
android:id="#+id/tv_kalp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="5"
android:textColor="#color/colorPrimary"
android:layout_alignParentStart="true"
android:layout_marginTop="25dp"
android:layout_marginStart="84dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:text="X"
android:textColor="#color/colorPrimary"
android:layout_alignParentStart="true"
android:layout_marginTop="35dp"
android:layout_marginStart="77dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="3">
<TextView
android:id="#+id/tv_soru"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:fontFamily="#font/incee"
android:gravity="center"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:textAlignment="gravity"
android:textSize="18sp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="5"
android:orientation="vertical">
<Button
android:id="#+id/btn_a"
android:layout_width="260dp"
android:layout_height="60dp"
android:textColor="#000"
android:background="#drawable/gradient"
android:gravity="center"
android:textAlignment="gravity"
android:fontFamily="#font/incee"
android:textSize="12sp"
android:layout_centerHorizontal="true"/>
<Button
android:id="#+id/btn_b"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_below="#+id/btn_a"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="#drawable/gradient"
android:fontFamily="#font/incee"
android:gravity="center"
android:textAlignment="gravity"
android:textColor="#000"
android:textSize="12sp" />
<Button
android:id="#+id/btn_c"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:background="#drawable/gradient"
android:fontFamily="#font/incee"
android:gravity="center"
android:textAlignment="gravity"
android:textColor="#000"
android:textSize="12sp"
android:layout_below="#+id/btn_b"
android:layout_marginTop="5dp"/>
<Button
android:id="#+id/btn_d"
android:layout_width="260dp"
android:layout_height="60dp"
android:textColor="#000"
android:background="#drawable/gradient"
android:gravity="center"
android:textAlignment="gravity"
android:fontFamily="#font/incee"
android:textSize="12sp"
android:layout_below="#+id/btn_c"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"/>
<Button
android:id="#+id/btn_infoA"
android:layout_width="40dp"
android:layout_height="45dp"
android:background="#drawable/info"
android:layout_centerVertical="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
<Button
android:id="#+id/btn_gec"
android:layout_width="65dp"
android:layout_height="60dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="1dp"
android:background="#drawable/next"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
<TextView
android:id="#+id/tv_skor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="0"
android:textColor="#000"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:text="SKOR :"
android:textColor="#000"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="50dp"
android:layout_marginBottom="5dp"/>
<Button
android:id="#+id/btn_reklam"
android:layout_width="50dp"
android:layout_height="45dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="5dp"
android:background="#drawable/plus"
android:onClick="startVideoAd"/>
<TextView
android:id="#+id/tv_kalp_kazan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="İzle Kazan"
android:layout_alignParentStart="true"
android:textSize="15sp"
android:textStyle="bold"
android:layout_alignParentBottom="true"
android:fontFamily="#font/incee"
android:textColor="#000"
android:layout_marginStart="55dp"
android:layout_marginBottom="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3101578796185185/4912585915">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
I think it's because the bannerview is lower than your screen! (Maybe you're using this layout for a fragment and your activity has a toolbar, am I right?)
Just put LinearLayout inside a ScrollView and see if it works.
Your layout design is not very well done, the buttons at the center (first RelativeLayout) are not constrained to the adjacent buttons, so they may overlap.
You should use a ConstraintLayout instead of RelativeLayout, the later is obsolete now.
You have several items with wrap_content height inside a layout that you want to stretch vertically, which is contradictory. This may cause views inside the inner RelativeLayouts to be hidden if they are smaller than the height.
weightSum is a property that is rarely useful because weights are calculated automatically, you should simply know that two views with 1 and 1 with use 50% each, and if you add another with weight 2 it will have proportionally that weight. So it will end up 25%, 25% and 50%.
There is no need to place the AdView inside a RelativeLayout if it is the only view there.
If you want the banner to be always visible, then simply place a default height (either wrap_content or a given height in dps). The other views will use the remaining space to calculate the weight space.
I recommend you to first study how different Layouts work before attempting to build your screen layout.
On the other hand, the AdView requires some additional configuration on your end to become shown, because if you did not setup some campaign to be shown, the view won't display anything.

Listview Item layout pushes the linearlayout off the screen

I am new to android and am trying to create a list view row item as follows:
On the far left of the listview item I need two stacked text views
In the center of the listview item I need an additional two stacked text view
On the far right I need a checkbox
I want to make the width of the center textviews a constant size, irrespective to the length of text.
Every time I adjust the middle linear layout, it pushes the checkbox off the screen unless I manually give it a width (which will not work for multiple screen sizes). Can someone please help?
I've tried using weights and all but I can't figure it out.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="left"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/starttime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:singleLine="true"
android:text="10:35am"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#929692"
android:textSize="12sp" />
<TextView
android:id="#+id/endtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:singleLine="true"
android:text="11:55am"
android:textColor="#929692"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/middle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_toRightOf="#id/left"
android:orientation="vertical">
<TextView
android:id="#+id/sessionname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:padding="2dp"
android:singleLine="true"
android:text="ok this is where my text goes it is very long
and it will push stuff off"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textSize="14sp" />
<TextView
android:id="#+id/location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:ellipsize="end"
android:singleLine="true"
android:text="#android:string/ok"
android:textColor="#929692" />
</LinearLayout>
<LinearLayout
android:id="#+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_toRightOf="#id/middle"
android:orientation="vertical">
<CheckBox
android:id="#+id/list_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:checked="false" />
</LinearLayout>
</RelativeLayout>
Used constraintlayout and it worked!

Layout larger than device screen causes app to crash

I am currently having an issue with a mobile app I am developing. The idea behind it being it displays the value of various variables from a passed object. As I have needed to add more and more objects to the layout xml file in order to display everything, the preview has since stopped displaying any objects besides the action bar and trying to start the activity using this layout crashes the app.
I have a feeling this may be due to the layout being larger than the virtual device screen, though there could be another cause i'm totally unaware of. Any help in this matter would be appreciated. This activity currently uses the Relative layout, would it resolve the issue to wrap the Relative layout in a Scrollview to make the activity scrollable?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Name"
android:id="#+id/RequestNameTextView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/RequestNameDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/RequestNameTextView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_margin="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Student ID"
android:id="#+id/RequestStudentIDTextView"
android:layout_below="#+id/RequestNameDisplay"/>
<TextView
android:id="#+id/RequestStudentIDDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/RequestStudentIDTextView"
android:layout_margin="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/RequestLocationTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/RequestStudentIDDisplay"
android:text="Location"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="#+id/RequestLocationDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/RequestLocationTextView"
android:layout_margin="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/RequestProblemTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/RequestLocationDisplay"
android:text="Problem Description"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="#+id/RequestProblemDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/RequestProblemTextView"
android:layout_margin="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/RequestStatusTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/RequestProblemDisplay"
android:text="Current Status"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/RequestStatusDisplay"
android:layout_below="#+id/RequestStatusTextView"
android:layout_margin="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="#+id/RequestAssignmentTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/RequestStatusDropDown"
android:text="Assigned To"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/RequestAssignmentDisplay"
android:layout_below="#+id/RequestAssignmentTextView"
android:layout_margin="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="#+id/RequestStatusUpdateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/RequestAssignmentDisplay"
android:text="Update Status to:"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/RequestStatusDropDown"
android:layout_below="#+id/RequestStatusUpdateTextView"
android:layout_margin="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="#+id/RequestAssignmentUpdateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/RequestStatusDropDown"
android:text="Assign Request To:"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/RequestAssignmentDropDown"
android:layout_below="#+id/RequestAssignmentUpdateTextView"
android:layout_margin="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<Button
android:id="#+id/RequestSaveChangesButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Save Changes" />
</RelativeLayout>
It is because your Relative Layout having Circular dependencies. From RequestAssignmentTextView to RequestStatusDropDown, your are having a circular dependency. Just change your 'below' element of RequestAssignmentTextView to avoid this error.

Android Textview settext issue in Samsung J5

I have a "problem" with my application and I don't know what has happened.
I have this interface:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#color/white"
android:gravity="center"
android:textColor="#color/black" />
<TextView
android:id="#+id/detailServiceTxtPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="-35dp"
android:ellipsize="end"
android:gravity="center"
android:maxLength="50"
android:singleLine="true"
android:textColor="#color/black" />
</LinearLayout>
I get the field value from a web service and set text in java code:
m_txtPhone.setText(m_currentService.PassengerPhone);
In all the devices where I check it this is the result:
But I have a problem in with Samsung J5 (5.1.1). When I try to set text in that TextView (and similars) I have this result:
It seems that I have some problem setting the text or I don't know. Any idea?
NOTE:
I implement the interface in this way because in other cases I do something like this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:orientation="vertical" >
<Button
android:id="#+id/detailServiceBtnClient"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#color/white"
android:drawableRight="#drawable/icon_detail"
android:gravity="left|center_vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="#string/detailServiceBtnClient"
android:textColor="#color/black" />
<TextView
android:id="#+id/detailServiceTxtClient"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="25dp"
android:layout_marginTop="-35dp"
android:ellipsize="end"
android:gravity="center"
android:maxLength="50"
android:singleLine="true"
android:textColor="#color/black" />
</LinearLayout>
You are using LinearLayout. In this layout items are added after each element. Your orientation is vertical, hence, it is below the button. Use RelativeLayout and then use alignTop and alignBottom properties of TextView.
android:alignTop="#+id/button"
android:alignBottom="#+id/button"
android:gravity="center"

how to center two textViews with different font-size

<LinearLayout
android:id="#+id/layout_information"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.17"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/text_view_destination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="\# Home in"
android:textColor="#color/solid_white"
android:textSize="19sp"
android:textStyle="bold"
android:layout_gravity="bottom"
/>
<TextView
android:id="#+id/text_view_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:textColor="#color/solid_white"
android:textSize="25sp"
android:textStyle="normal"
android:layout_gravity="bottom"
/>
</LinearLayout>
I want to center the two textViews vertically,
but I want them to be aligned to one line at their bottom.
Now they are alined to the same bottom,
but they are at the bottom of their parent layout.
How can I do this?
I have thought to wrap their current layout parent ("parent1") with another layout
("parent2")
and make "parent1" be in the center of "parent2".
Is there another way without adding elements?
If your problem is that both views are aligned at the bottom of their parent you can use this.
Both views are still aligned to the same bottom and centered on the screen.
Your layout looks like a part of a bigger XML (weight=0.17), that is why I have used fill_parent on layout_width.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_information"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.17"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/text_view_destination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="\# Home in"
android:textColor="#color/solid_white"
android:textSize="19sp"
android:textStyle="bold" />
<TextView
android:id="#+id/text_view_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:text="\# Home in"
android:textColor="#color/solid_white"
android:textSize="25sp"
android:textStyle="normal"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/text_view_destination"
android:layout_alignBaseline="#id/text_view_destination" />
</RelativeLayout>
try this way
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_information"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical|bottom"
android:orientation="horizontal" >
<TextView
android:id="#+id/text_view_destination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="HOme in"
android:textColor="#color/solid_white"
android:textSize="19sp"
android:textStyle="bold" />
<TextView
android:id="#+id/text_view_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textColor="#color/solid_white"
android:textSize="25sp"
android:text="Home out"
android:textStyle="normal" />
</LinearLayout>

Categories