Search code examples
androidandroid-layoutandroid-xmlandroid-relativelayout

Weight in xml - Android


I have a xml that is bellow :

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    card_view:cardCornerRadius="10dp"
    card_view:cardUseCompatPadding="true">

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="@dimen/Item_Rows_Height">


        <LinearLayout
            android:id="@+id/Items_Layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/list_item"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_gravity="right"
                android:layout_marginRight="10dp"
                android:layout_weight="1"
                android:gravity="right"
                android:textColor="#000000"
                android:textSize="20dp"/>

            <TextView
                android:id="@+id/txt_Comment"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_gravity="right"
                android:layout_marginRight="10dp"
                android:layout_weight="1"
                android:gravity="right"
                android:text="HELLO"
                android:textColor="#000000"
                android:textSize="20dp"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_weight="1"
                android:gravity="left"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/image_Share"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:src="@mipmap/ic_launcher"/>

                <ImageView
                    android:id="@+id/image_BackGround"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:src="@mipmap/ic_launcher"/>

                <ImageView
                    android:id="@+id/image_Download"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:src="@mipmap/ic_launcher"/>

                <ImageView
                    android:id="@+id/image_CountVisit"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:src="@mipmap/ic_launcher"/>

                <ImageView
                    android:id="@+id/image_CountDownload"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left"
                    android:layout_weight="1"
                    android:adjustViewBounds="true"
                    android:src="@mipmap/ic_launcher"/>

            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_toRightOf="@+id/Items_Layout"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/image_item"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:adjustViewBounds="true"/>
        </LinearLayout>
    </RelativeLayout>
</android.support.v7.widget.CardView>

I need to this result:

enter image description here


Solution

  • check this.

    <?xml version="1.0" encoding="utf-8"?>
    
    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        card_view:cardCornerRadius="10dp"
        card_view:cardUseCompatPadding="true">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:baselineAligned="false"
            android:orientation="horizontal"
            android:weightSum="2">
    
    
            <LinearLayout
                android:id="@+id/Items_Layout"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="2dp"
                android:layout_weight="1.4"
                android:orientation="vertical">
    
                <TextView
                    android:id="@+id/list_item"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="HELLO"
                    android:textColor="#000000"
                    android:textSize="20dp" />
    
                <TextView
                    android:id="@+id/txt_Comment"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="HELLO"
                    android:textColor="#000000"
                    android:textSize="20dp" />
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:orientation="horizontal">
    
                    <ImageView
                        android:id="@+id/image_Share"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher" />
    
                    <ImageView
                        android:id="@+id/image_BackGround"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher" />
    
                    <ImageView
                        android:id="@+id/image_Download"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher" />
    
                    <ImageView
                        android:id="@+id/image_CountVisit"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher" />
    
                    <ImageView
                        android:id="@+id/image_CountDownload"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher" />
    
                </LinearLayout>
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="2dp"
                android:layout_weight=".6"
                android:orientation="vertical">
    
                <ImageView
                    android:id="@+id/image_item"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:contentDescription="@string/app_name"
                    android:scaleType="center"
                    android:src="@mipmap/ic_launcher" />
            </LinearLayout>
        </LinearLayout>
    </android.support.v7.widget.CardView>