I have several LinearLayouts (See image at bottom and a piece of code). There is a text on each button and an image under the text. But there is an issue. When the application runs on a mobile with lower resolution the image hides text. How do I prevent this happening?
I set layout_height to 0pt to let layout_weight take care of this.
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0pt"
android:orientation="horizontal">
<Button
android:id="@+id/button1"
android:layout_weight="1"
android:layout_width="0pt"
android:layout_height="match_parent"
android:text="@string/button_pin1"
android:background="@drawable/button_blue"
android:layout_margin="2dp"
android:drawableBottom="@mipmap/ic_arrow_left" />
<Button
android:id="@+id/button2"
android:layout_weight="1"
android:layout_width="0pt"
android:layout_height="match_parent"
android:text="@string/button_pin2"
android:background="@drawable/button_green"
android:layout_margin="2dp"
android:drawableBottom="@mipmap/ic_arrow_right" />
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0pt"
android:orientation="horizontal">
<Button
android:id="@+id/button3"
android:layout_weight="1"
android:layout_width="0pt"
android:layout_height="match_parent"
android:text="@string/button_pin3"
android:background="@drawable/button_yellow"
android:layout_margin="2dp"
android:drawableBottom="@mipmap/ic_arrow_up"/>
<Button
android:id="@+id/button4"
android:layout_weight="1"
android:layout_width="0pt"
android:layout_height="match_parent"
android:text="@string/button_pin4"
android:background="@drawable/button_purple"
android:layout_margin="2dp"
android:drawableBottom="@mipmap/ic_arrow_down"/>
</LinearLayout>
Thank you for your answers.
EDIT (jaydroider):
I have tried your approach, but this is what i get updated image. In android studio I have taken a look at different screen sizes and this code will not fill the whole screen. I do not know if I am doing something bad.
Here are my updated codes:
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context="com.jigsik.arduinocontrol.Pin8aActivity">
<LinearLayout style="@style/CoreLayout">
<TextView
android:id="@+id/myText"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout style="@style/CoreLayout">
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/stop_all"
android:onClick="stopAll"
android:background="@drawable/button_red"
android:layout_margin="2dp"
android:drawableBottom="@mipmap/ic_stop"/>
</LinearLayout>
<LinearLayout style="@style/CoreLayout">
<Button
android:id="@+id/button1"
style="@style/Button.Blue"
android:text="@string/button_pin1"
android:drawableBottom="@mipmap/ic_arrow_left" />
<Button
android:id="@+id/button2"
style="@style/Button.Green"
android:text="@string/button_pin2"
android:drawableBottom="@mipmap/ic_arrow_right"/>
</LinearLayout>
<LinearLayout style="@style/CoreLayout">
<Button
android:id="@+id/button3"
style="@style/Button.Yellow"
android:text="@string/button_pin3"
android:drawableBottom="@mipmap/ic_arrow_up"/>
<Button
android:id="@+id/button4"
style="@style/Button.Purple"
android:text="@string/button_pin4"
android:drawableBottom="@mipmap/ic_arrow_down"/>
</LinearLayout>
<LinearLayout style="@style/CoreLayout">
<Button
android:id="@+id/button5"
style="@style/Button.Orange"
android:text="@string/button_pin5"
android:drawableBottom="@mipmap/ic_arrow_right"/>
<Button
android:id="@+id/button6"
style="@style/Button.Azure"
android:text="@string/button_pin6"
android:drawableBottom="@mipmap/ic_arrow_left"/>
</LinearLayout>
<LinearLayout style="@style/CoreLayout">
<Button
android:id="@+id/button7"
style="@style/Button.Pink"
android:text="@string/button_pin7"
android:drawableBottom="@mipmap/ic_arrow_down"/>
<Button
android:id="@+id/button8"
style="@style/Button.Grey"
android:text="@string/button_pin8"
android:drawableBottom="@mipmap/ic_arrow_up"/>
</LinearLayout>
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="CoreLayout">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:orientation">horizontal</item>
<item name="android:weightSum">2</item>
</style>
<style name="Button">
<item name="android:layout_weight">1</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">2dp</item>
<item name="android:layout_gravity">center</item>
<item name="android:gravity">center</item>
<item name="android:padding">10dp</item>
</style>
<style name="Button.Blue">
<item name="android:background">@drawable/button_blue</item>
</style>
<style name="Button.Green">
<item name="android:background">@drawable/button_green</item>
</style>
<style name="Button.Yellow">
<item name="android:background">@drawable/button_yellow</item>
</style>
<style name="Button.Purple">
<item name="android:background">@drawable/button_purple</item>
</style>
<style name="Button.Orange">
<item name="android:background">@drawable/button_orange</item>
</style>
<style name="Button.Azure">
<item name="android:background">@drawable/button_azure</item>
</style>
<style name="Button.Pink">
<item name="android:background">@drawable/button_pink</item>
</style>
<style name="Button.Grey">
<item name="android:background">@drawable/button_grey</item>
</style>
EDIT: I think this situation does not have a solution I would like it have. In my opinion there is only one way to accomplish this task. I have to make a second layout file for smaller screens and change it to achieve the desired behaviour (smaller images etc). Thanks for answers guys. I would not find the solution without brainstorming with you :-).