0

I want to create a header which contains an ImageView and three Buttons. I have done some coding but the problem is that when we run our app, the header only displays the image and the Buttons are not showing.

My Activity:

 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);
    }
}

My 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>
4

1 回答 1

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);

    }
}
于 2012-06-07T07:47:50.380 回答