Reputation: 21
Above is the image of my design but it is not as desired, I want few editing in this grid and those editing are are as follow:
TextView_1
and fill the available space on its left and right?TextView_1
and TextView_2 & 3
externally i.e. 32dp (Half of the height of ImageView) for both rows, I want theirs height to be stretched equally according to ImageView?Here is My code:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:layout_rowSpan="2"
app:srcCompat="@drawable/ic_home_black_24dp"
android:id="@+id/row_image"
android:minHeight="64dp"
android:minWidth="64dp"/>
<TextView
android:text="TextView_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:layout_columnSpan="2"
android:id="@+id/row_name"
android:minHeight="32dp"
android:layout_gravity="center_horizontal"/>
<TextView
android:text="TextView_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="34"
android:layout_row="1"
android:layout_column="2"
android:id="@+id/row_price"
android:minHeight="32dp"/>
<TextView
android:text="TextView_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="66"
android:layout_row="1"
android:layout_column="1"
android:id="@+id/row_disc"
android:minHeight="32dp"/>
</GridLayout>
Upvotes: 0
Views: 7278
Reputation: 1378
remove from textview row 0 col 1
android:layout_gravity="center_horizontal"
and add to textview row 0 col 1 textview row 1 col 1 textview row 1 col 2
android:gravity="center"
android:textAlignment="center"
should be look like this
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:layout_rowSpan="2"
app:srcCompat="@drawable/ic_home_black_24dp"
android:id="@+id/row_image"
android:minHeight="64dp"
android:minWidth="64dp"/>
<TextView
android:layout_columnWeight="70"
android:gravity="center"
android:textAlignment="center"
android:text="TextView_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:layout_columnSpan="2"
android:id="@+id/row_name"
android:minHeight="32dp"
/>
<TextView
android:gravity="center"
android:textAlignment="center"
android:text="TextView_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="34"
android:layout_row="1"
android:layout_column="2"
android:id="@+id/row_price"
android:minHeight="32dp"/>
<TextView
android:gravity="center"
android:textAlignment="center"
android:text="TextView_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="66"
android:layout_row="1"
android:layout_column="1"
android:id="@+id/row_disc"
android:minHeight="32dp"/>
</GridLayout>
Upvotes: 4