首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

为啥inflate其他的View过来却无法占满父布局

2013-09-21 
为何inflate其他的View过来却无法占满父布局?想设计一个FrameLayout,里面有一个WebView,WebView上方叠着一

为何inflate其他的View过来却无法占满父布局?
想设计一个FrameLayout,里面有一个WebView,WebView上方叠着一个透明的LinearLayout(id为middleLayout),当在无网的情况下,将LinearLayout变为不透明,挡住WebView,提示用户无法联网。

布局如下:


        android:orientation="vertical" />

</FrameLayout>


无网时触发后台的callQuestion函数:

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

当中的R.layout.detail_no_result如下:

<?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" />

为何这个TextView无法占满(fill_parent)整个middleLayout??? android 布局
[解决办法]
LinearLayout.LayoutParams ly = new LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT);
middleLayout.addView(view,ly); 

热点排行