Skip to content Skip to sidebar Skip to footer

Layout Items Adjustment Issue

I am trying to design layout like below but I am unable to design. I don't know how set layout without dp. How can I do without assigning dp to height & weight? Items should be

Solution 1:

You have opened <RelativeLayout> but didn't closed it. Try this code:

<RelativeLayoutxmlns: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_centerInParent="true"><android.support.v7.widget.CardViewandroid:id="@+id/card_view_news"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:layout_marginBottom="10dp"android:background="@drawable/bg"card_view:cardCornerRadius="5dp"card_view:cardElevation="2dp"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:padding="10dp"android:weightSum="2"><ImageViewandroid:id="@+id/NewsImage"android:layout_width="wrap_content"android:layout_height="0dp"android:layout_weight="1"android:scaleType="fitXY" /><TextViewandroid:id="@+id/NewsTitle"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight=".166"android:ellipsize="end"android:hint="News"android:singleLine="true"android:textColor="@color/primarytext"android:textStyle="bold" /><TextViewandroid:id="@+id/NewsDescription"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight=".5"android:ellipsize="end"android:hint="No News Feed"android:maxLines="3"android:text="TextView"android:textSize="12sp" /><TextViewandroid:id="@+id/News_Channel"android:layout_width="wrap_content"android:layout_height="0dp"android:layout_weight=".166"android:background="@drawable/bg"android:ellipsize="end"android:maxLines="1"android:padding="5dp"android:text="TextView"android:textColor="#FFFF"android:textSize="10sp"android:textStyle="bold" /><TextViewandroid:id="@+id/News_Time"android:layout_width="wrap_content"android:layout_height="0dp"android:layout_weight=".166"android:text="TextView"android:textColor="@color/colorPrimary"android:textSize="10sp"android:textStyle="bold" /></LinearLayout></android.support.v7.widget.CardView></RelativeLayout>

Solution 2:

If you will give constant height to card view it will not vary, and you can get your desired layout.

 <android.support.v7.widget.CardView
    android:id="@+id/card_view_news"
    android:layout_width="wrap_content"
    android:layout_height="300dp"
    android:layout_centerInParent="true"
    android:layout_marginBottom="10dp"
    android:background="@drawable/bg"
    card_view:cardCornerRadius="5dp"
    card_view:cardElevation="2dp">

Post a Comment for "Layout Items Adjustment Issue"