我想创建一个包含ImageView和三个按钮的标头。我做了一些编码,但问题是,当我们运行我们的应用程序时,标题只显示图像,而按钮没有显示。
我的活动:
public class Header extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.header);
}
}
我的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:scaleType="fitXY"
android:src="@drawable/header" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/mid_belt"
android:orientation="horizontal"
android:weightSum="90" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="10"
android:background="@drawable/selector"
android:onClick="click"
android:text="Latest"
android:textColor="#ffffff"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="10"
android:background="@drawable/selector"
android:text="News Room"
android:textColor="#ffffff"
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="10"
android:background="@drawable/selector"
android:text="Featured"
android:textColor="#ffffff"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
答案 0 :(得分:0)
你已经解决了你的问题,就像你班上的代码一样:
public class Header extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.header);
setContentView(R.layout.main);
}
}