为什么我的观点不填写父母?

时间:2012-02-28 00:44:12

标签: java android

我有两个布局,这是父布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/layoutTop"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="90"
        android:background="#FF0000"
        android:gravity="center"
        android:orientation="vertical" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layoutBottom"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="10"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/txtTimer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Time: 00:00:00"
            android:textColor="#FF0000"
            android:textSize="25dip" />
    </LinearLayout>

</LinearLayout>

这是儿童布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00FF00"
    android:orientation="vertical" >


        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                android:gravity="center"
                android:text="Hello World" />

        </LinearLayout>
</LinearLayout>

但是,当我将子视图放在id / layoutTop中时,它并不像它应该的那样填充父视图。这是结果:

enter image description here

这是替换id / layoutTop内容的代码:(通过来自孩子的事件调用此代码被删除)

public void OnVictory(GamePanel sender, GamePanel next) {
    if(next != null){
        gamePanel.removeView(sender);
        gamePanel.addView(next);
        next.triggerOnDisplay();
    }else{
        Toast.makeText(getBaseContext(), "Victory!", Toast.LENGTH_LONG).show();
    }
}

发件人是那里的旧视图,接下来是要放置的那个,而gamePanel是id / layoutTop

这就是内部布局的创建方式:

private void initialize() {
   LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   layoutInflater.inflate(R.layout.appetizerfakeout,this);
}

为什么我的内部视图没有填充父级?

0 个答案:

没有答案