I have used Relative layout with some views. I need to align the views in horizontally, but the views are not displaying same in all the screen size devices?
<RelativeLayout
android:id="#+id/layout_relative"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_marginTop="-5dp"
android:background="#007DD7">
<TextView
android:id="#+id/text1_login"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="45dp"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:backgroundTint="#color/white"
android:gravity="center"
android:shadowRadius="10.0"
android:text="1"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp" />
<TextView
android:id="#+id/text2_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_login"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="45dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Login"
android:textColor="#color/white"
android:textSize="20sp" />
<View
android:id="#+id/1_line"
android:layout_centerHorizontal="#+id/text1_login"
android:layout_width="70dp"
android:layout_height="2dp"
android:layout_marginLeft="90dp"
android:layout_marginTop="30dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"/>
<TextView
android:id="#+id/text1_delivery"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="170dp"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:shadowRadius="10.0"
android:text="2"
android:gravity="center"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"/>
<TextView
android:id="#+id/text2_delivery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_delivery"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="25dp"
android:gravity="center_horizontal"
android:maxLines="2"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Delivery"
android:textColor="#color/add_contact_selected"
android:textSize="20sp" />
<View
android:id="#+id/2_line"
android:layout_centerHorizontal="#+id/text1_delivery"
android:layout_width="80dp"
android:layout_height="2dp"
android:layout_marginLeft="215dp"
android:layout_marginTop="30dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"/>
<TextView
android:id="#+id/text1_payment"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="300dp"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:gravity="center"
android:shadowRadius="10.0"
android:text="3"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"/>
<TextView
android:id="#+id/text2_payment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_payment"
android:gravity="center_horizontal"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="260dp"
android:maxLines="2"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Payment"
android:textColor="#color/add_contact_selected"
android:textSize="20sp"
/>
</RelativeLayout>
You need to use LinearLayout with android:orientation="horizontal" and play with android:layout_weight to allign your views.
I've edited your code:
<LinearLayout
android:id="#+id/layout_linear"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_marginTop="-5dp"
android:background="#007DD7"
android:orientation="horizontal">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="#+id/text1_login"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:backgroundTint="#color/white"
android:gravity="center"
android:shadowRadius="10.0"
android:text="1"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp" />
<TextView
android:id="#+id/text2_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_login"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Login"
android:textColor="#color/white"
android:textSize="20sp" />
<View
android:id="#+id/1_line"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="#+id/text1_delivery"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:shadowRadius="10.0"
android:text="2"
android:gravity="center"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"/>
<TextView
android:id="#+id/text2_delivery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_delivery"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:maxLines="2"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Delivery"
android:textColor="#color/add_contact_selected"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="#+id/text1_payment"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:gravity="center"
android:shadowRadius="10.0"
android:text="3"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"/>
<TextView
android:id="#+id/text2_payment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_payment"
android:gravity="center_horizontal"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:maxLines="2"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Payment"
android:textColor="#color/add_contact_selected"
android:textSize="20sp"
/>
</LinearLayout>
</LinearLayout>
Update: add the horizontal line between circles:
<RelativeLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/text1_login"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:backgroundTint="#color/white"
android:gravity="center"
android:shadowRadius="10.0"
android:text="1"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/text2_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_login"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Login"
android:textColor="#color/white"
android:textSize="20sp"
android:layout_centerHorizontal="true" />
<View
android:id="#+id/1_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"
android:layout_marginTop="30dp"
android:layout_toRightOf="#+id/text1_login" />
</RelativeLayout>
<RelativeLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<View
android:id="#+id/2_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"
android:layout_marginTop="30dp"
android:layout_toLeftOf="#+id/text1_delivery" />
<TextView
android:id="#+id/text1_delivery"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:shadowRadius="10.0"
android:text="2"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"
android:gravity="center"
android:layout_centerHorizontal="true" />
<View
android:id="#+id/22_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"
android:layout_marginTop="30dp"
android:layout_toRightOf="#+id/text1_delivery" />
<TextView
android:id="#+id/text2_delivery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_delivery"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:maxLines="2"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Delivery"
android:textColor="#color/add_contact_selected"
android:textSize="20sp"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<View
android:id="#+id/3_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/white"
android:backgroundTint="#color/add_contact_selected"
android:layout_marginTop="30dp"
android:layout_toLeftOf="#+id/text1_payment" />
<TextView
android:id="#+id/text1_payment"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:gravity="center"
android:shadowRadius="10.0"
android:text="3"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/text2_payment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text1_payment"
android:gravity="center_horizontal"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:maxLines="2"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Payment"
android:textColor="#color/add_contact_selected"
android:textSize="20sp"
android:layout_centerHorizontal="true" />
</RelativeLayout>
To align views horizontally , you should use Linear Layout with horizontal orientation and assign weights to each child views.
Check this example which i have written using your layout -
<LinearLayout
android:id="#+id/layout_relative"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_marginTop="-5dp"
android:orientation="horizontal"
android:background="#007DD7">
<TextView
android:id="#+id/text1_login"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="45dp"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:backgroundTint="#color/white"
android:gravity="center"
android:shadowRadius="10.0"
android:text="1"
android:layout_weight="1"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp" />
<TextView
android:id="#+id/text2_login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="45dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:text="Login"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/text1_delivery"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:layout_gravity="center"
android:layout_marginLeft="170dp"
android:layout_marginTop="10dp"
android:background="#drawable/circle"
android:shadowRadius="10.0"
android:text="2"
android:gravity="center"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:backgroundTint="#color/add_contact_selected"/>
</LinearLayout>
I saw all the answers people who has suggest to use LinearLayout.One thing you have to know very clearly.By using the Relative or Linear we can achieve all the layout design.
First you have to analyse which design will be good.Implementation may be depends on three things.
1.Easy designing
2.Layout performance
3.How much you know about attributes of layout.
My suggestion also Linear only for your implementation but some times multiple inner linear layout will cause performance issue and this also you should aware of it.
How we are developing the code is not important,how we are optimizing the code is very important.
Related
I am learning to create UI in XML now, and I'm struggling with such a problem.
I create UI which looks like this: UI in Android Studio
And on the phone it looks like this: How it looks in reality (screenshot from a phone)
How to reduce these vertical spaces?
I want to get rid of this: These marked spaces
This is LinearLayout, and these are much bigger than I want them to be.
Here's my XML code for this UI:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="101dp"
android:layout_marginBottom="10dp"
android:layout_weight="0"
android:orientation="horizontal">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_marginTop="16dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="16dp"
android:layout_weight="1"
android:paddingTop="16dp"
android:text="Yooooo"
android:textAlignment="textEnd"
android:textSize="50sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="0"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<Button
android:layout_marginTop="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#color/md_theme_dark_error"
android:text="CLEAR ALL"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:textStyle="bold"
android:textSize="20sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="/"
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:layout_width="0dp"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="*"
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:layout_width="0dp"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="+"
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:layout_width="0dp"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="-"
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:layout_width="0dp"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="="
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_marginTop="1dp"
android:layout_width="1dp"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="7"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="8"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"/>
<Button
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="9"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="245dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="1dp"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:text="4"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"/>
<Button
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="5"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"/>
<Button
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="6"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="265dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="1dp"
android:layout_height="120dp"
android:layout_marginRight="3dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="1"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"/>
<Button
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="2"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"/>
<Button
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="6"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Thanks very much for every helpful hint/answer!!!
I tried changing the weight, reducing DPI spaces, and setting the android:layout_marginTop/Bottom to 10 dpi, I thought it would stop it from increasing the spaces.
You need to reduce the layout_height property for the Linear Layout and for the Button .
And as an advice if you want to learn UI creation using XML just try playing around with the editor and test different things it will be much easier to learn & memorise this way.
I've created a calculator app, and it works fine, but there's one question - why the background becomes transparent when i close the app by performing home gesture? Here's how it looks:
how to repair this? Thanks, any help appreciated.
Here's the code for this UI, MDC Android:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginBottom="5dp"
android:layout_weight="0"
android:layout_gravity="bottom"
android:orientation="horizontal"
>
<TextView
android:id="#+id/textViewResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginRight="10dp"
android:layout_marginBottom="1dp"
android:layout_weight="2"
android:text=""
android:textAlignment="textEnd"
android:textSize="50sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginTop="0dp"
android:orientation="horizontal"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:id="#+id/buttonDivide"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="/"
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="#+id/buttonMultiply"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="*"
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="#+id/buttonMinus"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="-"
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="#+id/buttonPlus"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="+"
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="#+id/buttonEquality"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="="
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom"
>
<Button
android:id="#+id/button7"
android:text="7"
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp" />
<Button
android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="8"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="9"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom">
<Button
android:id="#+id/button4"
android:text="4"
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp"
/>
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="5"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="6"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom">
<Button
android:id="#+id/button1"
android:text="1"
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp" />
<Button
android:id="#+id/button2"
android:text="2"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="3"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp">
<Button
android:id="#+id/buttonPoint"
android:text="."
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp" />
<Button
android:id="#+id/button0"
android:text="0"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="#+id/buttonDelete"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="DEL"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:textColor="#color/md_theme_dark_error"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="60dp"
android:orientation="horizontal"
android:layout_gravity="bottom">
<Button
android:id="#+id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="CLEAR"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:textColor="#color/md_theme_dark_error"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I tried disabling the night mode of the system, and apparently in white mode the problem doesn't appear. So the dark mode is causing the problem.
If the dark mode from your phone does that, then you can check res->values->themes->themes.xml(night) and set the default background color.
Another fix is to set the background in the LinearLayout.
"android:background="#ffffff"" / "android:background="#color/your_color""
Example:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/your_color"
android:padding="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginBottom="5dp"
android:layout_weight="0"
android:layout_gravity="bottom"
android:orientation="horizontal"
>
<TextView
android:id="#+id/textViewResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginRight="10dp"
android:layout_marginBottom="1dp"
android:layout_weight="2"
android:text=""
android:textAlignment="textEnd"
android:textSize="50sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginTop="0dp"
android:orientation="horizontal"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:id="#+id/buttonDivide"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="/"
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="#+id/buttonMultiply"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="*"
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="#+id/buttonMinus"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="-"
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="#+id/buttonPlus"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="+"
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="#+id/buttonEquality"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="="
android:textAlignment="center"
android:textColor="#color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom"
>
<Button
android:id="#+id/button7"
android:text="7"
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp" />
<Button
android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="8"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="9"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom">
<Button
android:id="#+id/button4"
android:text="4"
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp"
/>
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="5"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="6"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom">
<Button
android:id="#+id/button1"
android:text="1"
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp" />
<Button
android:id="#+id/button2"
android:text="2"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="3"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp">
<Button
android:id="#+id/buttonPoint"
android:text="."
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp" />
<Button
android:id="#+id/button0"
android:text="0"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="#+id/buttonDelete"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="DEL"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:textColor="#color/md_theme_dark_error"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="60dp"
android:orientation="horizontal"
android:layout_gravity="bottom">
<Button
android:id="#+id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="CLEAR"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:textColor="#color/md_theme_dark_error"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
This is xml code of my layout.its not displaying in API16 but its working properly in API
23,but its not working under versions.notging to display.
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dividerHeight="10dp"
android:id="#+id/list_primary">
</ListView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text14"
android:text="Taken"
android:textColor="#color/black"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text16"
android:text="Skip"
android:textColor="#color/black"
android:layout_marginTop="-25dp"
android:layout_gravity="center"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dismiss"
android:id="#+id/text15"
android:textColor="#color/black"
android:layout_gravity="right"
android:layout_marginTop="-25dp"
android:layout_marginRight="20dp"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:background="#mipmap/btn1"
android:layout_marginLeft="15dp"
android:id="#+id/btn_taken" />
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:background="#mipmap/btn2"
android:id="#+id/btnskip"
android:layout_gravity="center"
android:layout_marginTop="-70dp"
/>
<Button
android:layout_width="70dp"
android:layout_height="70dp"
android:background="#mipmap/btn3"
android:id="#+id/btndismiss"
android:layout_marginRight="20dp"
android:layout_gravity="right"
android:layout_marginTop="-70dp"
/>
</LinearLayout>
list_view.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="vertical"
android:elevation="5dp"
android:background="#drawable/listview">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:orientation="horizontal"
android:background="#drawable/logback">
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/label_medname"
android:layout_marginTop="10dp"
android:layout_marginLeft="15dp"
android:text="Medicine Name"
android:textColor="#000"
android:textSize="15dp"/>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/text_mediname"
android:layout_marginTop="10dp"
android:layout_marginLeft="15dp"
android:text="Name"
android:textColor="#000"
android:textSize="15dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:background="#drawable/logback">
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/label_quan"
android:layout_marginTop="10dp"
android:text="Quantity :"
android:layout_marginLeft="15dp"
android:textColor="#000"
android:textSize="15dp"/>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/text_quantity"
android:layout_marginTop="10dp"
android:text="Quantity"
android:layout_marginLeft="15dp"
android:textColor="#000"
android:textSize="15dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:background="#drawable/logback">
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/label_when"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="15dp"
android:text="When :"
android:textColor="#000"
android:textSize="15dp"/>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/text_when"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="15dp"
android:text="When"
android:textColor="#000"
android:textSize="15dp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
how can i fix this?
every thing is exactly same but data is not displaying in the list. Please i'm badly stuck here and i really need some fast help. Waiting for some positive response !
I have two TextViews which I want to be centered (in the middle) and they should have a fix Size of about 30 dp, how can I achieve that?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_weight="0.5"
android:padding="7dp"
android:textSize="30sp"
android:layout_marginRight="20dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="N"
android:background="#color/black"
android:textColor="#color/white"
android:id="#+id/textView1" android:gravity="center" />
<TextView
android:layout_weight="0.5"
android:padding="7dp"
android:textSize="30sp"
android:layout_marginRight="20dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="N"
android:background="#color/black"
android:textColor="#color/white"
android:id="#+id/textView2" android:gravity="center"/>
If I understand you correctly you want to use
android:gravity="center"
in your LinearLayout
Something similar to this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:padding="7dp"
android:textSize="30sp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="N"
android:background="#color/black"
android:textColor="#color/white"
android:id="#+id/textView1" android:gravity="center"
android:layout_marginRight="10dp" />
<TextView
android:padding="7dp"
android:textSize="30sp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="N"
android:background="#color/black"
android:textColor="#color/white"
android:id="#+id/textView2" android:gravity="center"
android:layout_marginLeft="10dp" />
Try this!!!!
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_weight="0.5"
android:padding="7dp"
android:textSize="30sp"
android:layout_marginRight="20dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="N"
android:background="#color/black"
android:textColor="#color/white"
android:id="#+id/textView1" />
<TextView
android:layout_weight="0.5"
android:padding="7dp"
android:textSize="30sp"
android:layout_marginRight="20dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="N"
android:background="#color/black"
android:textColor="#color/white"
android:id="#+id/textView2" />
I am keeping 9 images in a 3 rows like a 3X3 matrix. I am getting error while we are providing layout_weightsum so i changed it to weightsum. still it is showing me error. I am using Andorid Studio.
Below is my code.
<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:id="#+id/third_screen">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scroll_screen3"
android:layout_alignParentTop="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/retreat_2"
android:id="#+id/screen3_view">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="CHOOSE YOUR RETREAT"
android:id="#+id/txt_welcome"
android:focusableInTouchMode="false"
android:layout_gravity="center_horizontal"
android:textSize="20sp"
android:textColor="#ffffffff"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:gravity="center_horizontal" />
<ImageView
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/hover"
android:src="#drawable/hover"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp" />
<LinearLayout
android:background="#drawable/outline1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="418dp"
android:layout_margin="20dp"
android:weightsum="3"
android:id="#+id/outline_pockets" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/first_line_pockets"
android:layout_weightsum="3"
android:layout_weight="1"
android:layout_marginTop="10dp">
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket11"
android:src="#drawable/img1"
android:layout_weight="1" />
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket12"
android:src="#drawable/img2"
android:layout_weight="1" />
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket13"
android:src="#drawable/img3"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/first_line_txt"
android:layout_gravity="center_vertical"
android:weightsum="3" >
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="UNREASONABLE JOY"
android:layout_gravity="center_horizontal"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:gravity="center_vertical|center_horizontal"
android:textSize="13sp"
android:layout_weight="1"
android:id="#+id/txt_pocket11" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="LIGHTEN UP"
android:layout_gravity="center_horizontal"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:gravity="center_vertical|center_horizontal"
android:textSize="13sp"
android:layout_weight="1"
android:id="#+id/txt_pocket12" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="RELEASING DISEASE"
android:id="#+id/txt_pocket13"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:textSize="13sp"
android:textIsSelectable="false"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/second_line_pockets"
android:weightsum="3"
android:layout_weight="1">
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket21"
android:src="#drawable/img4"
android:layout_weight="1" />
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket22"
android:src="#drawable/img5"
android:layout_weight="1" />
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket23"
android:src="#drawable/img6"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="#+id/second_line_txt"
android:weightsum="3" >
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="BEYOND FEVER"
android:autoText="false"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="13sp"
android:gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:id="#+id/txt_pocket21" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="UNSHAKEABLE LOVE"
android:layout_gravity="center_horizontal"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="13sp"
android:gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:id="#+id/txt_pocket22" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="PEACEFUL PARENTING"
android:textSize="13sp"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:id="#+id/txt_pocket23" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/third_line_pockets"
android:weightsum="3"
android:layout_weight="1">
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket31"
android:src="#drawable/img7"
android:layout_weight="1" />
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket32"
android:src="#drawable/img8"
android:layout_weight="1" />
<ImageView
android:layout_width="60dp"
android:layout_height="80dp"
android:id="#+id/pocket33"
android:src="#drawable/img9"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/third_line_txt"
android:weightsum="3"
android:layout_marginBottom="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="GETTING UNSTUCK"
android:autoText="false"
android:layout_gravity="center_vertical"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:gravity="center_vertical|center_horizontal"
android:textIsSelectable="false"
android:textSize="13sp"
android:layout_weight="1"
android:id="#+id/txt_pocket31" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="WARRIOR MONK"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:layout_gravity="center_vertical"
android:gravity="center_vertical|center_horizontal"
android:textSize="13sp"
android:layout_weight="1"
android:id="#+id/txt_pocket32" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="FILLING YOUR CUP"
android:lines="2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:layout_gravity="center_vertical"
android:gravity="center_vertical|center_horizontal"
android:textSize="13sp"
android:singleLine="false"
android:layout_weight="1"
android:id="#+id/txt_pocket33" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="80dp"
android:id="#+id/no_more"
android:src="#drawable/no_more"
android:layout_marginTop="10dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/retreat_quiz"
android:src="#drawable/retreat_quiz"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
The correct spelling for the attribute is weightSum, not weightsum or layout_weightsum.
However, the system can calculate the sum for you. You can just omit the attribute altogether.