Android: 为布局设置固定高度?

Android: Setting a fixed Height for Layout?

我正在尝试制作以下 'card' 布局,它显示了如何将图像和布局中包含的所有内容设置为固定高度,模仿现实生活中的水平卡片。

到目前为止我做了什么:

下面的 XML 是我填充到 GridView 适配器中的单个网格项;这是上面提到的 'cards'.

之一
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginLeft="@dimen/feed_item_margin"
        android:layout_marginRight="@dimen/feed_item_margin"
        android:background="@drawable/bg_card"
        android:orientation="vertical"
        android:paddingBottom="@dimen/feed_item_padding_top_bottom"
        android:paddingTop="@dimen/feed_item_padding_top_bottom" >

        <ImageView
            android:id="@+id/grid_banner"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentTop="true"
            android:focusable="false"
            android:focusableInTouchMode="false" 
            android:background="@drawable/ic_launcher"/>

        <TextView
            android:id="@+id/bannerTitle"
            android:layout_width="285dp"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/grid_image"
            android:layout_alignLeft="@id/grid_image"
            android:layout_alignRight="@id/grid_image"
            android:layout_alignTop="@id/grid_image"
            android:layout_marginLeft="15sp"
            android:layout_marginTop="300sp"
            android:shadowColor="#000000"
            android:shadowDx="1.0"
            android:shadowDy="1.0"
            android:shadowRadius="5.0"
            android:textColor="#FFFFFF"
            android:textSize="25sp" />
    </LinearLayout>

</LinearLayout>

我知道我可以为根 LinearLayout 设置一个固定值,但这会影响通过不同的移动设备查看吗?比如,50dp 在平板电脑上看起来会很小吗?我错了吗?

一张卡片有四个元素要显示

  1. 图片
  2. "V" 图标
  3. 标题(白色文字)
  4. 描述(灰色文本)

因为标题和描述在某些地方与图片重叠,所以我建议您使用 RelativeLayout 并设置

  1. 卡片在运行时的高度取决于设备的屏幕宽度,因此它在所有设备上看起来都相似。

  2. 为不同类型的设备使用 Values 文件夹,并从那里设置 dp 大小。