伙计们我需要用三个按钮制作页脚,左右按钮应该占用屏幕左右两侧的25%,并且中间的图片应占用屏幕的50%,而不会留下任何空间它们之间。在android中如何用三个按钮创建页脚?
如果有人能帮上忙,那真是太好了。
我想发布需要的页脚图像,但我不允许共享图像。
伙计们我需要用三个按钮制作页脚,左右按钮应该占用屏幕左右两侧的25%,并且中间的图片应占用屏幕的50%,而不会留下任何空间它们之间。在android中如何用三个按钮创建页脚?
如果有人能帮上忙,那真是太好了。
我想发布需要的页脚图像,但我不允许共享图像。
这就是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:weightSum="4" android:layout_alignParentBottom="true">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="hello"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="2" android:text="hello"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="hello"/>
</LinearLayout>
</RelativeLayout>
这是它的外观:
这就是我想要的,我在你的代码中做了一些改变,它对我很有帮助。谢谢。 – user1740281 2013-03-21 06:12:02
写布局XML如下。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4">
<Button android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="25%"
android:layout_weight="1"/>
<Button android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="50%"
android:layout_weight="2"/>
<Button android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="25%"
android:layout_weight="1"/>
</LinearLayout>
线性布局应放置在一个相对的布局,使其对齐父母的底部。
android:layout_alignParentBottom="true"
所以你的最终布局将类似于以下
<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"
>
<!-- Root element should wrap to parent size. -->
<!-- Your view xml codes. -->
<!--Bottom bar layout should be in root element. Parent should be Relative layout so that we can always align to parent bottom-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="4">"
<Button android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="25%"
android:layout_weight="1"/>
<Button android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="50%"
android:layout_weight="2"/>
<Button android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="25%"
android:layout_weight="1"/>
</LinearLayout>
</RelativeLayout>
希望这会解决您的问题。
伙计们,谢谢大家的回答。我能够实现我想要的,但问题是,页脚并没有固定在底部,而是来自中间。 – user1740281 2013-03-19 09:51:27
我修改了我的答案。请看一下。如果正确,则将其标记为已接受。 – Midhere 2013-03-19 10:12:23
在这里,谢谢你的回答。 – user1740281 2013-03-25 10:11:29
如果您想要在所有活动中自定义底部栏,那么您需要在所有活动中包含布局。 我想下面的代码可以帮助你:
创建布局derectory bottomlayout.xml和复制下面里面的代码并使用合适的图片。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="@android:color:black"
android:gravity="center_horizontal" >
<ImageButton
android:id="@+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:background="@drawable/img1" />
<ImageButton
android:id="@+id/btn_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:background="@drawable/img2" />
<ImageButton
android:id="@+id/btn_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:background="@drawable/img3" />
</LinearLayout>
包括上面所有活动的xml在像底部:
<的LinearLayout 机器人:ID = “@ + ID/bottombar” 机器人:layout_width =” wrap_content“ android:layout_height =”50dp“ android:layout_alignParentBottom =”true“ android:la yout_alignParentLeft = “真” 机器人:layout_alignParentRight = “真” 机器人:背景= “@机器人:颜色:黑” 安卓重力= “CENTER_HORIZONTAL”>
下面写的代码中的所有.java文件您在.xml布局文件中包含bottonlayout。
ImageButton btn1=(ImageButton)findViewById(R.id.btn_1);
ImageButton btn2=(ImageButton)findViewById(R.id.btn_2);
ImageButton btn3=(ImageButton)findViewById(R.id.btn_3);
btn1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
// Your Code Here....
}
});
btn2.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
// Your Code Here....
}
});
btn3.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
// Your Code Here....
}
});
谢谢你的回答 – user1740281 2013-03-25 10:10:20
可以使用tabhost,并在底部设置其位置。有一个参考[*这里**](http://stackoverflow.com/q/2677698/1050058)。但它不鼓励使用像iPhone一样的底部标签。 – 2013-03-19 07:15:31