【发布时间】:2013-11-12 03:55:51
【问题描述】:
我想要一个这样的响应式主屏幕:
图片是使用 MS Paint 绘制的
每个菜单项(图片+标签)都实现了复合视图(LinearLayout包含ImageView和TextView)...复合视图的布局文件如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_gravity="center"
android:gravity="center" >
<ImageView
android:id="@+id/menu_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
</ImageView>
<TextView
android:id="@+id/menu_item_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="15sp" >
</TextView>
</LinearLayout>
我无法实现如上图的设计。我用过 RelativeLayout
这是布局代码。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_height="match_parent"
android:layout_width="match_parent" >
<com.cibl.c_ebankinfo.compoundviews.MenuItem
android:id="@+id/offer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" >
</com.cibl.c_ebankinfo.compoundviews.MenuItem>
<com.cibl.c_ebankinfo.compoundviews.MenuItem
android:id="@+id/privilege"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/offer" >
</com.cibl.c_ebankinfo.compoundviews.MenuItem>
<com.cibl.c_ebankinfo.compoundviews.MenuItem
android:id="@+id/notice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/privilege" >
</com.cibl.c_ebankinfo.compoundviews.MenuItem>
<com.cibl.c_ebankinfo.compoundviews.MenuItem
android:id="@+id/contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/offer" >
</com.cibl.c_ebankinfo.compoundviews.MenuItem>
<com.cibl.c_ebankinfo.compoundviews.MenuItem
android:id="@+id/services"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/contact" >
</com.cibl.c_ebankinfo.compoundviews.MenuItem>
<com.cibl.c_ebankinfo.compoundviews.MenuItem
android:id="@+id/complaint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/services" >
</com.cibl.c_ebankinfo.compoundviews.MenuItem>
<com.cibl.c_ebankinfo.compoundviews.MenuItem
android:id="@+id/etoken"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/contact" >
</com.cibl.c_ebankinfo.compoundviews.MenuItem>
<com.cibl.c_ebankinfo.compoundviews.MenuItem
android:id="@+id/locator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/etoken" >
</com.cibl.c_ebankinfo.compoundviews.MenuItem>
<com.cibl.c_ebankinfo.compoundviews.MenuItem
android:id="@+id/product"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/locator" >
</com.cibl.c_ebankinfo.compoundviews.MenuItem>
</RelativeLayout>
这是结果
最左边的项目显示正确,但其余项目显示不正确。中间列和右列项都使用 layout_toRightOf 属性,所以我知道它们为什么不能正确显示。
【问题讨论】:
-
为什么没用过gridview?
-
查看这个链接,我之前用过它,也许它会帮助你androidhive.info/2011/12/android-dashboard-design-tutorial
-
@Raghunandan 我试过 GridView .....我设置了一个 GridView 来填满整个屏幕,但我不能让列自动调整大小以适应屏幕......这是结果@987654322 @ 和代码在这里 pastebin.com/Zt0TjRjE ..... 我将 GridView 涂成红色以验证它确实填满了屏幕
-
@Shuaib 设置项目之间的垂直和水平间距,使其充满整个屏幕。使用 gridview 正是你所需要的
-
您可以使用 zohreh 提到的线性布局中的项目的权重
标签: android android-layout android-relativelayout