我试图制作以下卡片'布局,显示布局中包含的图像和所有内容如何设置为固定高度,模拟真实水平卡片。
到目前为止我所做的:
以下XML是我向GridView适配器充气的单个网格项;这是上面提到的卡片之一'。
<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在平板电脑上看起来很小?我错了吗?
答案 0 :(得分:2)
您需要为一张卡片显示四个元素
因为标题和描述在某些方面与图像重叠,所以我建议您使用RelativeLayout
并设置
卡在运行时的高度取决于设备的屏幕宽度,使其在所有设备上看起来相似。
将Values文件夹用于不同类型的设备,并从那里设置dp的大小。