android實現底部功能表列

來源:互聯網
上載者:User

android程式,許多時候需要功能表列顯示在底部或頂部,但是沒有很好的組建供程式員調用,過自訂了一個視圖,用來實現底部功能表列,效果如:

實現的主要代碼:

 

@Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
       
requestWindowFeature(Window.FEATURE_NO_TITLE);
       
setContentView(R.layout.main);

        linearLayout = (LinearLayout) findViewById(R.id.home);
       
linearLayout.setOnClickListener(new OnClickListener() {
           
@Override
            public void onClick(View v) {
               
linearLayout
                       
.setBackgroundResource(R.drawable.tab_two_highlight);
               
publish.setBackgroundResource(R.drawable.tab_one_normal);
               
change.setBackgroundResource(R.drawable.tab_one_normal);
               
more.setBackgroundResource(R.drawable.tab_one_normal);
            }

        });
        linearLayout
       
.setBackgroundResource(R.drawable.tab_two_highlight);

        publish = (LinearLayout) findViewById(R.id.publish);
       
publish.setOnClickListener(new OnClickListener() {
            @Override

            public void onClick(View v) {
               
publish.setBackgroundResource(R.drawable.tab_two_highlight);
               
linearLayout.setBackgroundResource(R.drawable.tab_one_normal);

                change.setBackgroundResource(R.drawable.tab_one_normal);

                more.setBackgroundResource(R.drawable.tab_one_normal);

            }
        });

        change = (LinearLayout) findViewById(R.id.change);
       
change.setOnClickListener(new OnClickListener() {
            @Override

            public void onClick(View v) {
               
change.setBackgroundResource(R.drawable.tab_two_highlight);
               
linearLayout.setBackgroundResource(R.drawable.tab_one_normal);

                publish.setBackgroundResource(R.drawable.tab_one_normal);

                more.setBackgroundResource(R.drawable.tab_one_normal);

            }
        });

        more = (LinearLayout) findViewById(R.id.more);
       
more.setOnClickListener(new OnClickListener() {
            @Override

            public void onClick(View v) {
               
more.setBackgroundResource(R.drawable.tab_two_highlight);
               
linearLayout.setBackgroundResource(R.drawable.tab_one_normal);

                publish.setBackgroundResource(R.drawable.tab_one_normal);

                change.setBackgroundResource(R.drawable.tab_one_normal);

            }
        });
    }

設定檔實現:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
   
android:orientation="horizontal" android:layout_width="fill_parent"
   
android:layout_height="wrap_content">
    <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
       
android:orientation="vertical" android:layout_width="80px"
       
android:layout_height="wrap_content" android:id="@+id/home"
       
android:background="@drawable/tab_one_normal">
        <TextView
android:layout_width="wrap_content"
           
android:layout_height="wrap_content" android:text="@string/home"
           
android:gravity="center" android:paddingTop="29px"
           
android:background="@drawable/home" />
    </LinearLayout>
   
<ImageView android:layout_width="wrap_content"
           
android:layout_height="wrap_content"  android:src="@drawable/line" />
   
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       
android:orientation="vertical" android:layout_width="80px"
       
android:layout_height="wrap_content"
android:background="@drawable/tab_one_normal"
       
android:id="@+id/publish">
        <TextView
android:layout_width="wrap_content"
           
android:layout_height="wrap_content" android:text="@string/publish"

            android:gravity="center" android:paddingTop="29px"

             android:background="@drawable/publish" />
   
</LinearLayout>
    <ImageView android:layout_width="wrap_content"

            android:layout_height="wrap_content" 
android:src="@drawable/line" />
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       
android:orientation="vertical" android:layout_width="80px"
android:id="@+id/change"
        android:layout_height="wrap_content"
android:background="@drawable/tab_one_normal">
        <TextView
android:layout_width="wrap_content"
           
android:layout_height="wrap_content" android:text="@string/change"

            android:gravity="center" android:paddingTop="29px"

             android:background="@drawable/change" />
   
</LinearLayout>
    <ImageView android:layout_width="wrap_content"

            android:layout_height="wrap_content" 
android:src="@drawable/line" />
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       
android:orientation="vertical" android:layout_width="80px"
android:id="@+id/more"
        android:layout_height="wrap_content"
android:background="@drawable/tab_one_normal">
        <TextView
android:layout_width="wrap_content"
           
android:layout_height="wrap_content" android:text="@string/more"
           
android:gravity="center" android:paddingTop="29px"
            
android:background="@drawable/more" />
    </LinearLayout>

</LinearLayout>

原始碼見:http://easymorse.googlecode.com/svn/trunk/android.bottom

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.