我试图做出如下'卡'布局,其中显示了图像和布局中包含的所有内容如何设置到一个固定的高度,它模仿一个真实的生活水平卡。Android:为布局设置固定高度?
我到目前为止做出:
以下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'文件夹分辨率并设置具体的值 – tyczj
为什么不尝试使用layoutWeight?你可以这样做,即使你需要明确地设置一个项目的高度,你也可以像@tyczj所说的那样做,并且有一个值文件夹来处理不同的设备。 – sparkyShorts