如何为我的Android应用程序创建页眉或页脚按钮栏
许多受欢迎的应用程序(如Google地图,Facebook,Foursquare等)在其大部分活动中都有页眉和/或页脚栏。这些标题通常包含非常有用的按钮,并且我想为我的应用程序创建一个。有谁知道他们是如何完成的?到目前为止我还找不到任何东西。如何为我的Android应用程序创建页眉或页脚按钮栏
这里是我的意思了一些照片: http://www.flickr.com/photos/calebgomer/6262815430 http://www.flickr.com/photos/calebgomer/6262815458
使用这种方式可以使您header-footer xml
并用它来任何您activity
也只需写代码,在报头中的控制 -footer曾在HeaderFooter.java并且可以访问它您的项目。
建立你的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);
}
}
我以前在android上工作过。我有工作的应用程序,我只是想让他们的GUI看起来更好。我会看看这些样本,看看我能做些什么。 谢谢! –
@Vinay不要给链接这个链接被打破。请更新您的链接。 – BBdev
设计带有页眉,页脚和body的Xml布局。每次扩展主要活动时,都必须通过膨胀所需布局来更改主体。
我认为你在这些布局中喜欢的元素是他们使用FrameLayout来显示下部的事实。
他们可能做这样的事情:
<LinearLayout android:orientation="vertical
.../>
<head layout element>
<FrameLayout element>
<footer layout element>
</LinearLayout>
使用LinearLayout页脚并为页脚使用FrameLayout有区别吗? –
这不是框架布局的页脚。内容窗格是框架布局。我编辑我的答案是更具体。 –
我明白你的意思了。我将LinearLayout中的“body”改为了FrameLayout,但我没有看到两者之间的区别。在这种情况下使用FrameLayout有没有实际的好处? –
这种方法工作得很好,谢谢! (唯一的问题是,页脚与屏幕底部之间的距离很小) –
@CalebGomer我已更新xml使用它,并且该问题将得到解决..我想如果noy – MKJParekh
修复它!再次感谢你的帮助。 –