【发布时间】:2015-01-08 15:27:50
【问题描述】:
我正在尝试制作以下“卡片”布局,该布局显示图像和布局中包含的所有内容如何设置为固定高度,模仿现实生活中的水平卡片。
到目前为止我所做的:
以下 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 在平板电脑上可能看起来很小?我错了吗?
【问题讨论】:
-
50dp 在任何设备上仍然是 50dp,它看起来很小,因为屏幕更大。如果你想为不同的屏幕分辨率设置不同的尺寸,你需要使用那些特定的
values文件夹分辨率并设置特定的值 -
为什么不尝试使用 layoutWeight?您可以这样做,即使您需要明确设置项目的高度,您也可以按照@tyczj 所说的进行操作,并拥有一个值文件夹来处理不同的设备。
标签: java android android-layout mobile cardlayout