2013年9月18日星期三

[Android] Why inflate Other View over but can not fill the parent layout ?

Want to design a FrameLayout, which has a WebView, WebView stacked with a transparent top LinearLayout (id is middleLayout), while in the case of no network will LinearLayout becomes opaque , blocking WebView, prompt the user can not be networked .

layout is as follows:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/detailWebView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="48dip" />

    <LinearLayout
        android:id="@+id/middleLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="48dip"
        android:background="#00000000"
        android:orientation="vertical" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="48dip"
        android:layout_gravity="top"
        android:background="@drawable/title_bg"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/back"
            android:layout_width="48dip"
            android:layout_height="fill_parent"
            android:background="#00000000"
            android:scaleType="fitCenter"
            android:src="@drawable/back" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#00000000"
        android:orientation="vertical" />

</FrameLayout>

no network is triggered when the background callQuestion function :

private void callQuestion(String result) {
if (result == "No result") {
LinearLayout middleLayout = (LinearLayout) findViewById(R.id.middleLayout);
middleLayout.setBackgroundColor(Color.WHITE);

View view = LayoutInflater.from(this).inflate(
R.layout.detail_no_result, null);
middleLayout.addView(view);
}
}

among R.layout.detail_no_result as follows:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/txt1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ff0"
    android:gravity="center"
    android:text="网络出问题了,点我刷新..."
    android:textSize="30sp" />

Why is this TextView can not fill (fill_parent) throughout middleLayout? ? ?
------ Solution ---------------------------------------- ----
LinearLayout.LayoutParams ly = new LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT);
middleLayout.addView(view,ly); 

没有评论:

发表评论