本文介绍了如何创建一个页眉或页脚按钮栏为我的Andr​​oid应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多流行的应用程序对大多数活动的头和/或页脚吧。这些头文件通常包括非常有用的按钮,和我想创建一个是我的应用程序。没有人知道他们是怎么做的?我一直没能找到任何东西为止。

Many popular apps like Google Maps, Facebook, Foursquare, etc. have header and/or footer bars on most of their activities. These headers often include very useful buttons, andI would like to create one for my app. Does anyone know how they are done? I haven't been able to find anything so far.

下面是我的意思的一些照片:http://www.flickr.com/photos/calebgomer/6262815430http://www.flickr.com/photos/calebgomer/6262815458

Here are some pictures of what I mean:http://www.flickr.com/photos/calebgomer/6262815430http://www.flickr.com/photos/calebgomer/6262815458

推荐答案

使用这种方式,你可以让你的页眉页脚的XML ,并用它来你的任何<$的C $ C>活动你也只需要为写code在页​​眉页脚的控件曾在 HeaderFooter.java 并能访问您的项目。

Using this way you can make your header-footer xml and use it to any of your activity also you just need to write code for the controls in header-footer once in HeaderFooter.java and can access it your project.

建立你的HederFooter.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" android:weightSum="10"
    android:id="@+id/commonlayout" android:background="#FFFFFF">
    <LinearLayout android:id="@+id/llheader"
        android:layout_width="fill_parent" android:layout_height="0dp"
        android:background="@drawable/bar" android:layout_weight="1">



        <RelativeLayout android:id="@+id/relativeLayout1"
            android:layout_width="fill_parent" android:layout_height="fill_parent"
            android:layout_gravity="center">
            <Button
                android:id="@+id/Button_HeaderFooterSubscribe"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginRight="2dp"
                android:layout_centerVertical="true"
                android:background="@drawable/subscribe"
                />
                <Button
                android:id="@+id/Button_logout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginRight="2dp"
                android:layout_centerVertical="true"
                android:background="@drawable/logout"
                />
                <Button
                android:id="@+id/Button_playlist"
                android:layout_marginLeft="2dp"
                android:layout_width="wrap_content"
                android:layout_centerVertical="true"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:background="@drawable/tempadd"
                />



</RelativeLayout>

    </LinearLayout>
    <LinearLayout android:id="@+id/lldata"
        android:layout_weight="8" android:layout_width="fill_parent"
        android:layout_height="0dp" android:background="#FFFFFF">


    </LinearLayout>

    <LinearLayout android:id="@+id/llfooter"
        android:layout_weight="1" android:layout_width="fill_parent"
        android:orientation="horizontal" android:layout_height="0dp"
        android:visibility="visible" android:background="@drawable/fbg"
        android:weightSum="5.0" android:gravity="center"
        android:layout_margin="0dp">

        <Button android:id="@+id/home" android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:layout_weight="1"
            android:background="@drawable/home" android:textColor="#FFFFFF"
            android:padding="10px"></Button>

        <Button android:id="@+id/issue" android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:layout_weight="1"
            android:background="@drawable/issue" android:textColor="#FFFFFF"
            android:padding="10px"></Button>

        <Button android:id="@+id/browse" android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:layout_weight="1"
            android:background="@drawable/browse" android:textColor="#FFFFFF"
            android:padding="10px"></Button>

        <Button android:id="@+id/search" android:layout_height="wrap_content"
            android:layout_width="wrap_content" android:layout_weight="1"
            android:background="@drawable/search" android:textColor="#FFFFFF"
            android:padding="10px"></Button>

        <Button android:layout_height="wrap_content" android:id="@+id/favorite"
            android:background="@drawable/favorite" android:layout_width="wrap_content"
            android:layout_weight="1"
            android:textColor="#FFFFFF" android:padding="10px"></Button>
    </LinearLayout>

</LinearLayout>

然后创建一个HeaderFooter.java活动

public class HeaderFooter extends Activity {
        public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.headerfooter);
        }
 }

现在扩展上面的活动,您的所有其他活动和膨胀您的特定观点的headerfooter.xml中间布局

public class Home extends HeaderFooter 
{
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            ViewGroup vg = (ViewGroup) findViewById(R.id.lldata);
            ViewGroup.inflate(Home.this, R.layout.home, vg);
        }
}

这篇关于如何创建一个页眉或页脚按钮栏为我的Andr​​oid应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 07:02