Layout spacing issue in a bigger size screen - java

Does anyone know why this is happening:
The letters boxes are not aligned correctly in the tablet screen which is 10" but it works just fine on 7" and 4.7" screen.
Here is my XML layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp"
android:id="#+id/alphabetPad" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/rowABCD"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnA"
android:layout_weight="1"
android:text="A"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnB"
android:layout_weight="1"
android:text="B"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/btnC"
android:layout_weight="1"
android:text="C"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/btnD"
android:layout_weight="1"
android:text="D"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/rowEFGH"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnE"
android:layout_weight="1"
android:text="E"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnF"
android:layout_weight="1"
android:text="F"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnG"
android:layout_weight="1"
android:text="G"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnH"
android:layout_weight="1"
android:text="H"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowIJKL">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnI"
android:layout_weight="1"
android:text="I"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnJ"
android:layout_weight="1"
android:text="J"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnK"
android:layout_weight="1"
android:text="K"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnL"
android:layout_weight="1"
android:text="L"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowMNOP">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnM"
android:layout_weight="1"
android:text="M"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnN"
android:layout_weight="1"
android:text="N"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnO"
android:layout_weight="1"
android:text="O"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnP"
android:layout_weight="1"
android:text="P"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowQRST">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnQ"
android:layout_weight="1"
android:text="Q"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnR"
android:layout_weight="1"
android:text="R"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnS"
android:layout_weight="1"
android:text="S"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnT"
android:layout_weight="1"
android:text="T"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowUVWX">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnU"
android:layout_weight="1"
android:text="U"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnV"
android:layout_weight="1"
android:text="V"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnW"
android:layout_weight="1"
android:text="W"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/btnX"
android:layout_weight="1"
android:text="X"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowYZ">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnBlank"
android:layout_weight="1"
android:text=""
android:visibility="invisible" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnY"
android:layout_weight="1"
android:text="Y"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/btnZ"
android:layout_weight="1"
android:text="Z"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/btnBlank"
android:layout_weight="1"
android:text=""
android:visibility="invisible" />
</LinearLayout>
</LinearLayout>
I am guessing the boxes are too big to fit. How can I make it so that no matter what screen size the app is being displayed on, the boxes always line up.
I tried changing the margin for each button, 1dp for larger screen and 2dp for smaller screen but that didn't help.
Help is greatly appreciated.

Just replace
android:layout_width = "wrap_content"
with
android:layout_width = "fill_parent"
Try the below layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp"
android:id="#+id/alphabetPad" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/rowABCD"
android:layout_weight="1">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnA"
android:layout_weight="1"
android:text="A"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnB"
android:layout_weight="1"
android:text="B"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/btnC"
android:layout_weight="1"
android:text="C"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/btnD"
android:layout_weight="1"
android:text="D"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/rowEFGH"
android:layout_weight="1">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnE"
android:layout_weight="1"
android:text="E"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnF"
android:layout_weight="1"
android:text="F"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnG"
android:layout_weight="1"
android:text="G"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnH"
android:layout_weight="1"
android:text="H"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowIJKL">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnI"
android:layout_weight="1"
android:text="I"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnJ"
android:layout_weight="1"
android:text="J"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnK"
android:layout_weight="1"
android:text="K"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnL"
android:layout_weight="1"
android:text="L"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowMNOP">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnM"
android:layout_weight="1"
android:text="M"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnN"
android:layout_weight="1"
android:text="N"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnO"
android:layout_weight="1"
android:text="O"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnP"
android:layout_weight="1"
android:text="P"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowQRST">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnQ"
android:layout_weight="1"
android:text="Q"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnR"
android:layout_weight="1"
android:text="R"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnS"
android:layout_weight="1"
android:text="S"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnT"
android:layout_weight="1"
android:text="T"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowUVWX">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnU"
android:layout_weight="1"
android:text="U"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnV"
android:layout_weight="1"
android:text="V"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnW"
android:layout_weight="1"
android:text="W"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/btnX"
android:layout_weight="1"
android:text="X"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/rowYZ">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnBlank"
android:layout_weight="1"
android:text=""
android:visibility="invisible" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnY"
android:layout_weight="1"
android:text="Y"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/btnZ"
android:layout_weight="1"
android:text="Z"
android:background="#drawable/letterstyle"
android:textColor="#FFFFFF"
android:layout_margin="2dp"
android:textSize="#dimen/btn_text"
android:textStyle="bold" />
<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/btnBlank"
android:layout_weight="1"
android:text=""
android:visibility="invisible" />
</LinearLayout>
Please check the modified layout I just posted in my answer. It is working fine for me when I tested. When you are specifying layout_weight in a linear layout, it is always better to use layout_width or layout_height as fill_parent, as the LinearLayout adjusts the layout according to the layout_weight attribute, regardless of the content inside the layout.
Let me know if it works for you too!

You can use TableLayout with android:stretchColumns="*" to force all columns to have the exact same width.
Example
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp"
android:stretchColumns="*" >
<TableRow android:layout_weight="1">
<Button android:text="A"
android:layout_height="match_parent"/>
<Button android:text="B"
android:layout_height="match_parent"/>
<Button android:text="C"
android:layout_height="match_parent"/>
<Button android:text="D"
android:layout_height="match_parent"/>
<Button android:text="E"
android:layout_height="match_parent"/>
</TableRow>
<TableRow android:layout_weight="1">
<Button android:text="F"
android:layout_height="match_parent"/>
<Button android:text="G"
android:layout_height="match_parent"/>
<Button android:text="H"
android:layout_height="match_parent"/>
<Button android:text="I"
android:layout_height="match_parent"/>
<Button android:text="J"
android:layout_height="match_parent"/>
</TableRow>
<TableRow android:layout_weight="1">
<Button android:text="K"
android:layout_height="match_parent"/>
<Button android:text="L"
android:layout_height="match_parent"/>
<Button android:text="M"
android:layout_height="match_parent"/>
<Button android:text="N"
android:layout_height="match_parent"/>
<Button android:text="O"
android:layout_height="match_parent"/>
</TableRow>
<TableRow android:layout_weight="1">
<Button android:text="P"
android:layout_height="match_parent"/>
<Button android:text="Q"
android:layout_height="match_parent"/>
<Button android:text="R"
android:layout_height="match_parent"/>
<Button android:text="S"
android:layout_height="match_parent"/>
<Button android:text="T"
android:layout_height="match_parent"/>
</TableRow>
</TableLayout>

Related

How to decrease the space between column

I have this table:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TableLayout
android:id="#+id/tableLayout"
android:layout_width="369dp"
android:layout_height="118dp"
android:layout_marginTop="224dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/q1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="A:" />
<TextView
android:id="#+id/q2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="15%" />
<TextView
android:id="#+id/q3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/editTextBackground"
android:layout_weight="1.5"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:textColor="#000000" />
<TextView
android:id="#+id/q4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="20%" />
<TextView
android:id="#+id/q5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/editTextBackground"
android:textColor="#000000"
/>
<TextView
android:id="#+id/q6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="25%" />
<TextView
android:id="#+id/q7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/editTextBackground"
android:textColor="#000000"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/a1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="B:" />
<TextView
android:id="#+id/a2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="15%" />
<TextView
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/editTextBackground"
android:textColor="#000000"
/>
<TextView
android:id="#+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="20%" />
<TextView
android:id="#+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/editTextBackground"
android:textColor="#000000"
/>
<TextView
android:id="#+id/b4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="25%" />
<TextView
android:id="#+id/b5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/editTextBackground"
android:textColor="#000000"
/>
</TableRow>
</TableLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
How to make the columns closer together?
To make less space between 15% and underscore?
Used below codes
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TableLayout
android:id="#+id/tableLayout"
android:layout_width="369dp"
android:layout_height="118dp"
android:layout_marginTop="224dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/q1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:text="A:" />
<TextView
android:id="#+id/q2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
android:text="15%" />
<TextView
android:id="#+id/q3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/editTextBackground"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:textColor="#000000" />
<TextView
android:id="#+id/q4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
android:text="20%" />
<TextView
android:id="#+id/q5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/editTextBackground"
android:textColor="#000000" />
<TextView
android:id="#+id/q6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
android:text="25%" />
<TextView
android:id="#+id/q7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/editTextBackground"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/a1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:text="B:" />
<TextView
android:id="#+id/a2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
android:text="15%" />
<TextView
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/editTextBackground"
android:textColor="#000000" />
<TextView
android:id="#+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
android:text="20%" />
<TextView
android:id="#+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/editTextBackground"
android:textColor="#000000" />
<TextView
android:id="#+id/b4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
android:text="25%" />
<TextView
android:id="#+id/b5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/editTextBackground"
android:textColor="#000000" />
</TableRow>
</TableLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Output :

Create separator between button

I have problem with create my button separator. This my buttons layout with my xml layout my create button.
This is fragment activity_swipe.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/searchDreamButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_selector"
android:gravity="center"
android:text="#string/search_dream"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
<Button
android:id="#+id/singInButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_selector"
android:gravity="center"
android:text="#string/sign_in"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
</LinearLayout>
but try make separator that this
Try this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="#android:color/holo_blue_bright"
>
<Button
android:id="#+id/searchDreamButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:background="#android:color/holo_blue_bright"
android:text="#string/search_dream"
android:textAllCaps="false"
/>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/black_color"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
/>
<Button
android:id="#+id/singInButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/holo_blue_bright"
android:gravity="center"
android:text="#string/sign_in"
android:textAllCaps="false"
/>
</LinearLayout>
try this my friend
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/searchDreamButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_selector"
android:gravity="center"
android:text="#string/search_dream"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000" />
<Button
android:id="#+id/singInButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#drawable/button_selector"
android:gravity="center"
android:text="#string/sign_in"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
</LinearLayout>

Android Java : Linear Layout vanishes when placed on another Linear Layout

I am working on the horizontal view for a basic Android calculator, and I have a LinearLayout called linearLayout2 that I am trying to place on top of linearLayout3, which contains the numbers 1, 2, 3, +, -, and (. The problem is that when I try to move linearLayout2 on top of linearLayout3, it immedietly vanishes to the top with 0 height.
Here is the XML code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:weightSum="1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/editText"
android:hint="#string/hint"
android:textSize="14dp"
android:background="#00000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout3"
android:orientation="horizontal"
android:weightSum="1"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:text="1"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button37"
android:layout_height="wrap_content" />
<Button
android:text="2"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button39"
android:layout_height="wrap_content" />
<Button
android:text="3"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button40"
android:layout_height="wrap_content" />
<Button
android:text="+"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button46"
android:layout_height="wrap_content" />
<Button
android:text="-"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button47"
android:layout_height="wrap_content" />
<Button
android:text="("
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button49"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout4"
android:orientation="horizontal"
android:weightSum="1"
android:layout_above="#+id/linearLayout5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:text="4"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button41"
android:layout_height="wrap_content" />
<Button
android:text="5"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button42"
android:layout_height="wrap_content" />
<Button
android:text="6"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button43"
android:layout_height="wrap_content" />
<Button
android:text="*"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button35"
android:layout_height="wrap_content" />
<Button
android:text="/"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button36"
android:layout_height="wrap_content" />
<Button
android:text=")"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button38"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout5"
android:orientation="horizontal"
android:weightSum="1"
android:layout_above="#+id/linearLayout6"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:text="7"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button44"
android:layout_height="wrap_content" />
<Button
android:text="8"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button45"
android:layout_height="wrap_content" />
<Button
android:text="9"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button48"
android:layout_height="wrap_content" />
<Button
android:text="+/-"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button50"
android:layout_height="wrap_content" />
<Button
android:text="%"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button51"
android:layout_height="wrap_content" />
<Button
android:text="^"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button52"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout6"
android:orientation="horizontal"
android:weightSum="1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
>
<Button
android:text="0"
android:layout_width="0dp"
android:layout_weight=".16667"
android:textAllCaps="false"
android:id="#+id/button25"
android:layout_height="wrap_content" />
<Button
android:text="."
android:layout_width="0dp"
android:layout_weight="0.3333"
android:textAllCaps="false"
android:id="#+id/button53"
android:layout_height="wrap_content" />
<Button
android:text="="
android:layout_width="0dp"
android:textAllCaps="false"
android:layout_weight="0.5"
android:id="#+id/button55"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2"
android:orientation="horizontal"
android:weightSum="1"
android:layout_above="#+id/linearLayout3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</LinearLayout>
<Button
android:text="Mode"
android:layout_width="0dp"
android:layout_weight="0.50"
android:textAllCaps="false"
android:id="#+id/button3"
android:background="#ffff5830"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Try to use Gridlayout instead of LinearLayout if you want to develop a calculator.
Your Layout2 is using wrap_content for height
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2"
android:orientation="horizontal"
android:weightSum="1"
android:layout_above="#+id/linearLayout3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</LinearLayout>
but there is no content in that group (no child views) so this is correct behaviour as there is no need to make group height bigger.
Also, if you want to stack Layout2 on Layout3 you may consider wrapping themtogether in FrameLayout (or another RelativeLayout)

Adjusting the gridview and roe of buttons

I am trying to adjust the space between grid view and buttons
I have posted figure
I am trying to attain that
XML
<?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:orientation="vertical" >
<!-- Top navigation bar for Restaurant Description Page -->
<TableRow
android:id="#+id/tableRow6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2sp" >
<RelativeLayout
android:id="#+id/TopNavigationBarRestaurantDesc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#726E6D" >
<!-- Back Button -->
<Button
android:id="#+id/TopNavigationBarRestaurantDescActivityBackButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="BACK"
android:textColor="#android:color/white"
android:textSize="12sp" />
<!-- Restaurant Description page name -->
<TextView
android:id="#+id/TopNavigationBarRestaurantDescActivityName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="TextView"
android:textColor="#android:color/white"
android:textSize="18sp"
android:textStyle="bold" />
<!-- Restaurant Description page Image -->
<ImageView
android:id="#+id/TopNavigationBarRestaurantDescActivityImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2sp" >
<TextView
android:id="#+id/RestaurantTimingsID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Timings"
android:textStyle="bold" />
</TableRow>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp" >
</LinearLayout>
<TableRow
android:id="#+id/BuyReservedButtonRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2sp" >
<Button
android:id="#+id/BuyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buy_button_shape"
android:paddingBottom="13dp"
android:paddingLeft="16dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Buy"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6sp" />
<Button
android:id="#+id/ReservedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/reserverd_button_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Reserve"
android:textColor="#android:color/white" />
</TableRow>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableRow
android:id="#+id/DescriptionTitleRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2sp" >
<GridView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="80dp"
android:gravity="center"
android:numColumns="3"
android:scrollbars="horizontal"
android:stretchMode="spacingWidthUniform" >
</GridView>
</TableRow>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp" >
</LinearLayout>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal" >
<Button
android:id="#+id/RestaurantDescriptionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Description"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantLocationButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Location"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantPhotosButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Photos"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantFriendsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Friends"
android:textColor="#android:color/white"
android:textSize="11sp" />
</LinearLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow7"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal" >
<Button
android:id="#+id/RestaurantSearchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_square_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Search"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantFeaturedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_square_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Featured"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantDealsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_square_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Deals"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantInviteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_square_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Invite"
android:textColor="#android:color/white"
android:textSize="11sp" />
<Button
android:id="#+id/RestaurantAccountButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_square_shape"
android:paddingBottom="13dp"
android:paddingLeft="13dp"
android:paddingRight="13dp"
android:paddingTop="13dp"
android:text="Account"
android:textColor="#android:color/white"
android:textSize="11sp" />
</LinearLayout>
</TableRow>
</LinearLayout>
</LinearLayout>
How to remove the space between the grid view and below row of buttons
How to remove the space below gridview
Try below segment of code, replace with your code and pls check once.
<TableRow
android:id="#+id/DescriptionTitleRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="2sp" >
<GridView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="80dp"
android:gravity="center"
android:numColumns="3"
android:scrollbars="horizontal"
android:stretchMode="spacingWidthUniform" >
</GridView>
</TableRow>

Change RelativeLayout to add a ListView

I have the following layout:
<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="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText
android:id="#+id/etShowLog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:lines="12"
android:textStyle="normal"
android:paddingLeft="2dip"
android:singleLine="false"
android:textColor="#999999"
android:textSize="14dip"
android:gravity="top"
android:layout_above="#+id/btnClear" />
<Button
android:id="#+id/btnClear"
android:background="#drawable/otherbuttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:shadowColor="#000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"
android:layout_alignParentBottom="true" />
<Button
android:id="#+id/btnSave"
android:background="#drawable/otherbuttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Trip"
android:layout_gravity="right"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:shadowColor="#000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
Which displays this:
How do I edit the layout so I can display a listview underneath:
like this,remember to keep listview height in a fixer value or use weight
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_marginBottom="200dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="0dp" android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"/>
<LinearLayout
android:layout_width="0px"
android:layout_height="wrap_content" android:layout_weight="1">
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2"/>
</LinearLayout>
</LinearLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:id="#+id/listView" android:layout_gravity="center"
android:layout_marginTop="-200dp"/>
</LinearLayout>
Wrap your Buttons in a LinearLayout. Give the ListView
android:"#+id/myListView"
android:layout_alignParentBottom="true"
and the newly created LinearLayout
android:layout_above="#id/myListView
So something like this should get you close
<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="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText
android:id="#+id/etShowLog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:lines="12"
android:textStyle="normal"
android:paddingLeft="2dip"
android:singleLine="false"
android:textColor="#999999"
android:textSize="14dip"
android:gravity="top"
android:layout_above="#+id/btnClear" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/myListView">
<Button
android:id="#+id/btnClear"
android:background="#drawable/otherbuttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:shadowColor="#000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"
android:layout_gravity="left"/>
<Button
android:id="#+id/btnSave"
android:background="#drawable/otherbuttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Trip"
android:layout_gravity="right"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:shadowColor="#000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"
android:layout_gravity="left" />
</LinearLayout>
<ListView
android:id="#+id/myListView"
...
android:layout_alignParentBottom="true"
</RelativeLayout>
I also took out the RelativeLayout properties that were in the Buttons and added android:layout_graivty="left"
android:layout_gravity="right"
Here is an alternative (but possibly old, I wrote it a few years ago) layout that includes two side-by-side listviews at the bottom of the view. There are a load of internal views, but you should be able to extract/convert what you need?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:id="#+id/LinearLayout" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/darkGrey">
<TableLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/TableLayout01"
android:background="#color/darkGrey">
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/TableRow01">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/LinearLayout01">
<TextView android:id="#+id/strap" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:textSize="18sp"
android:text="Pace/Distance/Time\nCalculator" android:textColor="#color/white"
android:width="170dip" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<Spinner android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="#+id/Spinner01"
android:layout_toRightOf="#+id/strap" android:prompt="#string/Presets" />
</LinearLayout>
</TableRow>
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/TableRow02">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/LinearLayout02">
<TextView android:id="#+id/topline1" android:layout_width="wrap_content"
android:layout_below="#+id/strap" android:layout_height="wrap_content"
android:text=" Hour" android:width="80dip" />
<TextView android:id="#+id/topline2" android:layout_width="wrap_content"
android:layout_below="#+id/strap" android:layout_height="wrap_content"
android:layout_toRightOf="#+id/topline1" android:text="Mins"
android:width="80dip" />
<TextView android:id="#+id/topline3" android:layout_width="wrap_content"
android:layout_below="#+id/strap" android:layout_height="wrap_content"
android:layout_toRightOf="#+id/topline2" android:text="Secs" />
</LinearLayout>
</TableRow>
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/TableRow03">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/LinearLayout03">
<EditText android:text="a" android:id="#+id/EditText01a"
android:layout_below="#+id/strap" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
android:maxLength="2" android:inputType="number" />
<EditText android:text="b" android:id="#+id/EditText01b"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:maxLength="2" android:inputType="number" />
<EditText android:text="c" android:id="#+id/EditText01c"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:maxLength="6" android:inputType="numberDecimal" />
<Button android:layout_width="fill_parent" android:text="Time"
android:layout_height="wrap_content" android:layout_weight="1"
android:onClick="myClickHandler" android:id="#+id/Button01" />
</LinearLayout>
</TableRow>
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/TableRow04">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/LinearLayout04">
<TextView android:id="#+id/midline1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=" Enter Distance (miles)" />
</LinearLayout>
</TableRow>
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/TableRow05">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/LinearLayout05">
<EditText android:layout_height="wrap_content"
android:text="#+id/EditText02" android:layout_width="wrap_content"
android:id="#+id/EditText02" android:inputType="numberDecimal"
android:maxLength="8" android:width="120dip" />
<Button android:id="#+id/Button02" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_toRightOf="#+id/EditText02"
android:layout_below="#+id/midline1" android:text="Distance"
android:layout_marginLeft="103dip" android:width="100dip"
android:maxWidth="100dip" android:onClick="myClickHandler" />
</LinearLayout>
</TableRow>
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/TableRow06">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/LinearLayout06">
<TextView android:id="#+id/topline1" android:layout_width="wrap_content"
android:layout_below="#+id/strap" android:layout_height="wrap_content"
android:text=" Hour" android:width="80dip" />
<TextView android:id="#+id/topline2" android:layout_width="wrap_content"
android:layout_below="#+id/strap" android:layout_height="wrap_content"
android:layout_toRightOf="#+id/topline1" android:text="Mins"
android:width="80dip" />
<TextView android:id="#+id/topline3" android:layout_width="wrap_content"
android:layout_below="#+id/strap" android:layout_height="wrap_content"
android:layout_toRightOf="#+id/topline2" android:text="Secs" />
</LinearLayout>
</TableRow>
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/TableRow07">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/LinearLayout07">
<EditText android:text="a2" android:id="#+id/EditText03a"
android:layout_below="#+id/strap" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
android:maxLength="2" android:inputType="number" />
<EditText android:text="b2" android:id="#+id/EditText03b"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:maxLength="2" android:inputType="number" />
<EditText android:text="c2" android:id="#+id/EditText03c"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:maxLength="6" android:inputType="numberDecimal" />
<Button android:layout_width="fill_parent" android:text="Pace"
android:layout_height="wrap_content" android:layout_weight="1"
android:onClick="myClickHandler" android:id="#+id/Button03" />
</LinearLayout>
</TableRow>
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/TableRow08"
android:background="#color/darkGrey">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/LinearLayout08"
android:background="#color/darkGrey">
<ListView android:id="#+id/ListView01"
android:layout_weight="1" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:background="#color/darkGrey" />
<ListView android:id="#+id/ListView02"
android:layout_weight="1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_toRightOf="#+id/ListView01"
android:background="#color/darkGrey2" />
</LinearLayout>
</TableRow>
</TableLayout>

Categories

Resources