布局项目调整问题 [英] Layout items adjustment issue

查看:67
本文介绍了布局项目调整问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试像下面那样设计布局,但是我无法设计.我不知道如何在没有dp的情况下设置布局.如何在不将 dp分配给height&的情况下怎么办?体重?

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?

项目在所有卡片视图中应以相同大小居中放置,并且可以不将dp分配给图像视图高度宽度,而所有图像应具有相同大小.

Items should be centered with same size of all card views and is it possible to not assign dp to image view height width but all images should be of same size.

XML

<RelativeLayout xmlns: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.CardView
    android: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">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="10dp"
        android:weightSum="2">

        <ImageView
            android:id="@+id/NewsImage"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:scaleType="fitXY" />

        <TextView
            android: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" />

        <TextView
            android: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" />

        <TextView
            android: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" />

        <TextView
            android: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>

我想要这个

推荐答案

如果您将卡片视图的高度保持不变,则它不会改变,并且您可以获得所需的布局.

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">

这篇关于布局项目调整问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆