我正在使用this lib进行水平滑动。检查以下代码
滑动功能正常但当我直接滑动时,则不会在网页视图上显示内容。 在下面的图片中显示了更多细节: -
在上面的图片之后,当我刷卡它很好但是当我们想要直接进入下一张幻灯片然后面对内容消失问题如下所示: -
然后它显示在下面
码
PageControl mPageControl = (PageControl) findViewById(R.id.page_control);
mSwipeView = (SwipeView) findViewById(R.id.swipe_view);
mSwipeView.setPageControl(mPageControl);
for (int i = 0; i < 10; i++) {
mSwipeView.addView(new FrameLayout(this));
}
for (int i = 0; i < 10; i++) {
((FrameLayout) mSwipeView.getChildContainer().getChildAt(i))
.addView(setupView());
count++;
}
setupView函数()
public View setupView() {
LayoutInflater layoutInflator = getLayoutInflater();
LinearLayout childlayout = (LinearLayout) layoutInflator.inflate(
R.layout.webview, Switcher, false);
// adding all the things in which define in below XML
return childlayout;
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/layClick"
android:layout_width="43dp"
android:layout_height="64dp"
android:background="@drawable/queslay"
android:gravity="left"
android:orientation="vertical" >
// some stuff
</LinearLayout>
<LinearLayout
android:id="@+id/main_question"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<WebView
android:id="@+id/ques"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/option_main"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/solution_confirm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@null"
android:gravity="center"
android:orientation="horizontal" >
// some stuff
</LinearLayout>
还会在“@ + id / option_main”上使用xml下面的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="wrap_content"
android:orientation="vertical" >
<!-- <FL><LL><FL></FL><BTN/></LL></FL> -->
<RelativeLayout
android:id="@+id/option_relative_a"
android:layout_width="fill_parent"
android:layout_margin="10dp"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/option_a"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="40dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/btn_a"
android:layout_width="47dp"
android:layout_height="19dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/opgrey"
android:gravity="center"
android:text="@string/a"
android:textColor="#ffffff"
android:textSize="12sp" />
<ImageView
android:id="@+id/ch_a"
android:layout_width="21dp"
android:layout_height="18dp"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/cross"
android:gravity="center"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:orientation="vertical" >
<WebView
android:id="@+id/ques_option_a"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/option_image_a"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignBottom="@+id/option_a"
android:background="@null" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/option_relative_b"
android:layout_width="fill_parent"
android:layout_margin="10dp"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/option_b"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="40dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/btn_b"
android:layout_width="47dp"
android:layout_height="19dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/opgrey"
android:gravity="center"
android:text="@string/b"
android:textColor="#ffffff"
android:textSize="12sp" />
<ImageView
android:id="@+id/ch_b"
android:layout_width="21dp"
android:layout_height="18dp"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/cross"
android:gravity="center"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:orientation="vertical" >
<WebView
android:id="@+id/ques_option_b"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/option_image_b"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignBottom="@+id/option_b"
android:background="@null" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/option_relative_c"
android:layout_width="fill_parent"
android:layout_margin="10dp"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/option_c"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="40dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/btn_c"
android:layout_width="47dp"
android:layout_height="19dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/opgrey"
android:gravity="center"
android:text="@string/c"
android:textColor="#ffffff"
android:textSize="12sp" />
<ImageView
android:id="@+id/ch_c"
android:layout_width="21dp"
android:layout_marginTop="5dp"
android:layout_height="18dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/cross"
android:gravity="center"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:orientation="vertical" >
<WebView
android:id="@+id/ques_option_c"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/option_image_c"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignBottom="@+id/option_c"
android:background="@null" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/option_relative_d"
android:layout_width="fill_parent"
android:layout_margin="10dp"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/option_d"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="40dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/btn_d"
android:layout_width="47dp"
android:layout_height="19dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/opgrey"
android:gravity="center"
android:text="@string/d"
android:textColor="#ffffff"
android:textSize="12sp" />
<ImageView
android:id="@+id/ch_d"
android:layout_width="21dp"
android:layout_height="18dp"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/greentick"
android:gravity="center"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:orientation="vertical" >
<WebView
android:id="@+id/ques_option_d"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/option_image_d"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/option_d"
android:background="@null" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/option_relative_e"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/option_e"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="40dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/btn_e"
android:layout_width="47dp"
android:layout_height="19dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/opgrey"
android:gravity="center"
android:text="@string/e"
android:textColor="#ffffff"
android:textSize="12sp" />
<ImageView
android:id="@+id/ch_e"
android:layout_width="21dp"
android:layout_height="18dp"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/greentick"
android:gravity="center"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:orientation="vertical" >
<WebView
android:id="@+id/ques_option_e"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/option_image_e"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignBottom="@+id/option_e"
android:background="@null" />
</RelativeLayout>
滑动工作正常,但直接将一张幻灯片放到不同的幻灯片时会遇到问题。
如果您过去也遇到过同样的问题,请帮助我。答案 0 :(得分:17)
这就是上面的闪烁问题,所以我可以阅读如此多的链接: -
https://code.google.com/p/android/issues/detail?id=20446
hardware accelerated webview slide-in animation flickering on ICS
WebView "flashing" with white background if hardware acceleration is enabled (Android 3.0+)
和
<强>代码强>
webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
上面的代码为我工作。