Aligning Two Linearlayout Side By Side Inside A Cardview
I am trying to align two TextViews OR LinearLayouts side by side in order to reach this cardView: I have used layout_gravity and layout_weight attributes inorder to solve this si
Solution 1:
For the part on the right you can use a TableLayout. Try to play with nesting layouts or switch to ConstraintLayout for better performance. Too many nested layout weights will quickly add up and create performance issues.
You can start fine tuning from the XML provided below. I removed the layout_weight from the CardView, if needed, add it back.
In preview it looks like this:
Layout XML:
<android.support.v7.widget.CardViewxmlns:android="http://schemas.android.com/apk/res/android"xmlns:card_view="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="5dp"android:orientation="horizontal"card_view:cardCornerRadius="5sp"card_view:cardElevation="5sp"card_view:contentPadding="16dp"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="2"android:gravity="center_vertical"android:orientation="horizontal"><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center_vertical"android:orientation="vertical"><TextViewstyle="@style/Base.TextAppearance.AppCompat.Headline"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Model Name"android:textColor="#ec1c24"android:textSize="16dp"android:textStyle="bold" /><TextViewandroid:id="@+id/plc_ModelName"style="@style/Base.TextAppearance.AppCompat.Body1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="#666666"android:textSize="36dp"android:textStyle="bold"tools:text="T-Max" /></LinearLayout><TableLayoutandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"><TableRow><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="3dp"android:text="Model ID:"android:textColor="#ec1c24"android:textSize="14dp"android:textStyle="bold" /><TextViewandroid:id="@+id/plc_ModelId"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="3dp"android:textSize="14dp"tools:text="12345678" /></TableRow><TableRow><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="3dp"android:text="IP:"android:textColor="#ec1c24"android:textSize="14dp"android:textStyle="bold" /><TextViewandroid:id="@+id/plc_localIp"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="3dp"android:textSize="14dp"tools:text="192.168.0.1" /></TableRow><TableRow><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="3dp"android:text="BS Version:"android:textColor="#ec1c24"android:textSize="14dp"android:textStyle="bold" /><TextViewandroid:id="@+id/plc_Version"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="3dp"android:textSize="14dp"tools:text="3.0.2.111" /></TableRow></TableLayout></LinearLayout></android.support.v7.widget.CardView></LinearLayout>
Post a Comment for "Aligning Two Linearlayout Side By Side Inside A Cardview"