首页 > Android > Android将ButtonBar放在屏幕底部

Android将ButtonBar放在屏幕底部

2010年5月31日 转烛 发表评论 阅读评论

  接上篇《Android将TAB选项卡放在屏幕底部》写。上篇提到ButtonBar的方式写底部button,试了试,看起来外观貌似比Tab好看,不过恐怕没有Tab管理Activity方便吧,毕竟一个Tab就是一个Activity,但是这样用Button的话,却并不如此,所以这样的涉及可能虽然好看点,但是管理起来却是相当麻烦。那么暂且把对activity的管理放在一边,只看界面的设计吧。

  要涉及这样的一个buttonbar,主要就是要用到style="@android:style/ButtonBar"这个风格。首先还是来看xml的设计,保存layout/bottombtn.xml

<?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">

    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:id="@+id/textOut"
        android:padding="5px" android:layout_weight="1"/>

    <LinearLayout style="@android:style/ButtonBar"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button android:id="@+id/button_weather" android:text="@string/bottom_weather"
            android:layout_width="0dip" android:layout_height="wrap_content"
            android:layout_weight="1"/>
        <Button android:id="@+id/button_mail" android:text="@string/bottom_mail"
            android:layout_width="0dip" android:layout_height="wrap_content"
            android:layout_weight="1"/>
        <Button android:id="@+id/button_train" android:text="@string/bottom_train"
            android:layout_width="0dip" android:layout_height="wrap_content"
            android:layout_weight="1"/>
        <Button android:id="@+id/button_sites" android:text="@string/bottom_sites"
            android:layout_width="0dip" android:layout_height="wrap_content"
            android:layout_weight="1"/>
        <Button android:id="@+id/button_stock" android:text="@string/bottom_stock"
            android:layout_width="0dip" android:layout_height="wrap_content"
             android:layout_weight="1"/>
    </LinearLayout>
</LinearLayout>

  然后就是关于这个的全部代码了:

package net.wangliping.popup;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class BottomBtn extends Activity {
    private static String LOG_TAG = "BottomBtn";
    private TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bottombtn);
       
        tv = (TextView)findViewById(R.id.textOut);
        tv.setText("http://tools.wangliping.net");
    }
}

  如此这般,就形成了下面的这个东西,虽然界面上看起来稍微美观一点,还是上面那句话:管理器Activity不一定很方便哦。

device

参考资料:

http://www.eoeandroid.com/redirect.php?tid=10709&goto=lastpost

分类: Android 标签: , ,
  1. zhaoblue
    2010年8月12日17:02 | #1

    我想问你一下,tab的宽度能改变啊?我想变小一点,也是改了android:layout_height,高度可以变小,但是面的字却不见了,请赐教!

  2. 转烛
    2010年8月12日21:07 | #2

    @zhaoblue
    请问你指的什么?这篇文章没有提到tab啊。

  3. zhaoblue
    2010年8月13日09:35 | #3

    @转烛 不好意思,发表错了,应该是提问在你的《Android将TAB选项卡放在屏幕底部》这篇文章里的。

  4. 转烛
    2010年8月13日14:07 | #4

    可以的。但是要做一些修改,你看到高度改变了但是字却遮住了,对吧?那是因为那个TabSpec的默认View的高度是64dp,也就是说,只要你设定的高度小于64dp,那么那个字就可能被遮住。解决方法就是利用TabSpec.setIndicator(View)而不是TabSpec.setIndicator(CharSequence),至于这个View你自己写一个就可以了。不过有个问题就是TabHost.addTab()这个函数,它会判定如果你用的是自己的View,那么它不会将那个底部的一条线画出来,这个可以处理一下。

  5. zhaoblue
    2010年8月16日10:48 | #5

    @转烛
    问你一个radiobutoon的问题,按下去的时候默认的是绿色,那么我如如果想让它变为黄色,还可以啊?

  6. 转烛
    2010年8月16日12:38 | #6

    @zhaoblue
    那你得自己做按钮,因为默认的RadioButton是绿色的,只有你自己做才可以随你自己的。

  1. 本文目前尚无任何 trackbacks 和 pingbacks.