为了使我的解释更短,我已经做了我想要实现的"模型".我想创建一个可重用的页眉,页脚和一个通用视图组,我可以填写所需的任何内容.ListActivity,GridView ......等

到目前为止,我尝试了几种不同的方法,但没有任何运气.我的第一次尝试是写出三个基本观点.一个可以充当容器的RelativeLayout.我曾经添加标题(工作),编写了GridView(工作),当尝试使用include连接页脚时,无论我使用哪种重力,它都不会锚定在屏幕的底部.
我目前正试图去学习android的视图系统.所以,我的第一个婴儿步骤.获取GridView处理从适配器中提取的图像.(基本上来自android网站的'Hello GridViews'演示 - 完成,有效)

下一步宝贝.尝试在GridView上面添加一个静态标头...灾难.我觉得我错过了一个重要的垫脚石来实现这个目标,任何正确方向的提示都会受到赞赏.我不太明白为什么包含Button的LinearLayout将GridView推出屏幕(它在HiearchyViewer中),当高度只是"wrap_content"时应该是"44dip".

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button
android:layout_width="fill_parent"
android:layout_height="44dip"
android:text="test"
/>
</LinearLayout>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="112dip"
android:numColumns="auto_fit"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
//编辑,修复xml.
编辑2010年10月25日:这是我现在使用的解决方案.每个活动都有自己的视图,活动会膨胀."可重用"视图包含在内
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<include layout="@layout/titlebar" />
<ListView
android:id="@+id/standingsListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="#FFF"
/>
<include layout="@layout/ad" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
至少我可以帮你解决"按钮"问题:你错过的神奇属性是 android:orientation
没有这个属性android android:orientation="horizontal"就像设置一样.这意味着每个视图都排列在水平线上,因此您的按钮右侧是您的网格,由于您的按钮具有LinearLayout,因此无法显示layout_width="fill_parent"
最后一个提示:少即是多,如果布局中只有一个视图,则删除布局并放置视图.(如果你只想在LinearLayout中有一个按钮)
| 归档时间: |
|
| 查看次数: |
2666 次 |
| 最近记录: |