好吧,你不能强迫在平板电脑上停留在底部,但如果是手机,你可以通过清单来做到这一点。但你可以做一些类似于底栏和顶栏的事情。
在本例中,我将向您展示如何使用合并轻松完成此操作,而无需使用 android ActionBar。
您需要创建的第一件事是您的main_activity.xml,在我的情况下,main_activity.xml 仅在RelativeLayout 上包含ImageView。这是代码。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<RelativeLayout android:id="@+id/RelativeLayout04"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<include layout="@layout/header" />
</RelativeLayout>
<ImageView
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_above="@+id/RelativeLayout03"
android:layout_below="@+id/RelativeLayout04"
android:layout_centerHorizontal="true"
android:src="@android:drawable/alert_dark_frame" />
<RelativeLayout android:id="@+id/RelativeLayout03"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<include layout="@layout/tryit" />
</RelativeLayout>
正如您在上面的代码中看到的,我在main_activity.xml 中放置了两个合并,一个在底部定义,一个在顶部定义。
这是假底栏xml。
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="0.14"
android:background="@drawable/dock" >
<ImageView
android:id="@+id/dark"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.14" />
<ImageView
android:id="@+id/stock"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.14" />
<ImageView
android:id="@+id/open"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.14" />
<ImageView
android:id="@+id/border"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.15" />
<ImageView
android:id="@+id/color"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.15"
/>
</LinearLayout>
我为LinearLayout 设置了一个固定的背景,并为onClicks 伪造了ImageView。
这里是顶部栏。 `
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="0.14"
android:background="@drawable/dock1"
android:layout_gravity="top">
<ImageView
android:id="@+id/darka"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.14" />
<ImageView
android:id="@+id/stocka"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.14" />
<ImageView
android:id="@+id/opena"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.14" />
<ImageView
android:id="@+id/bordera"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.15" />
<ImageView
android:id="@+id/colora"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.15"
/>
</LinearLayout>
`
这也从上面的底栏复制粘贴。只需将一件事从android:layout_alignParentBottom="true" 更改为android:layout_alignParentTop="true",您就会在底部和顶部得到一个actionBar。在这种情况下你不需要使用 ActionBar 所以我建议你使用Theme.Holo.NoActionBar
这是图像结果:- http://i.imgur.com/N8uKg6v.png
这是我现在正在做的一个项目。几乎完成了所有工作,但仍在努力设计。希望我的回答对你有所帮助。如果您觉得有趣,请投票给答案。
此致。 〜科什