I have a TableLayout
with rows containing Button
. I want all the buttons to be of the same width but they act like their width is match_parent
when they are rendered even though I've given them a specific width. They are not handled anywhere in Java, so the problem should lie in the XML only.
Here's my XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mridulahuja.kudamm.activities.ComponentDetailsActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/light_green_background"
android:scaleType="fitXY"
android:alpha="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:background="@null"
android:scrollbars="vertical"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.mridulahuja.kudamm.tools.ExpandableTextView
android:id="@+id/txtComponentInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="component info"
android:textColor="#000000"
android:textSize="20sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_height="10dp"
android:layout_width="match_parent"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="@+id/btnDataAtAGlance"
android:layout_height="wrap_content"
android:layout_width="250dp"
android:gravity="center"
android:textSize="18sp"
android:textColor="#ffffff"
android:background="@drawable/green_button_style"
android:text="Data at a glance"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_height="10dp"
android:layout_width="match_parent"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="@+id/btnDimensionsAtAGlance"
android:layout_height="wrap_content"
android:layout_width="250dp"
android:gravity="center"
android:layout_gravity="center"
android:padding="10sp"
android:textSize="18sp"
android:textColor="#ffffff"
android:background="@drawable/green_button_style"
android:text="Dimensions at a glance"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_height="10dp"
android:layout_width="match_parent"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="@+id/btnDownloadPdfCatalogue"
android:layout_height="wrap_content"
android:layout_width="250dp"
android:gravity="center"
android:layout_gravity="center"
android:padding="10sp"
android:textSize="18sp"
android:textColor="#ffffff"
android:background="@drawable/green_button_style"
android:text="PDF Catalogue"
/>
</TableRow>
</TableLayout>
</ScrollView>
</RelativeLayout>
This is the view rendered on Android Studio:
And this is the view rendered on mobile: (see the first button => this is happening will all buttons when I make their XML similar)
Why is this happening?