想设计一个FrameLayout,里面有一个WebView,WebView上方叠着一个透明的LinearLayout(id为middleLayout),当在无网的情况下,将LinearLayout变为不透明,挡住WebView,提示用户无法联网。布局如下:<?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>无网时触发后台的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布局
<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>无网时触发后台的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布局
解决方案 »
- socket啊!昨天下午5点到现在,只睡了4个小时。求助。
- 请问 如何在Android模拟器中 设置时间?
- Barnacle Wifi Tether 有人研究过吗?
- 如何实现滑动控件
- android mapview里做的自定义标记怎么去掉?
- SyncML联系人同步
- android 4.3 BLE onCharacteristicWrite没有回调
- 为什么要设置成全局变量
- 小白求助Android Studio无法创建AVD并提示An error occurred while creating the AVD. See idea.l
- Android View如何边绘制边左移动?
- 拿到一个APK,怎么准确地判断它是debug签名还是release签名?
- 为什么我TabHost的setIndicator设置了图片,但是我的应用显示却显示不出来呢
middleLayout.addView(view,ly);