gpt4 book ai didi

java - 不工作 ViewFlipper

转载 作者:行者123 更新时间:2023-11-30 02:39:01 28 4
gpt4 key购买 nike

对不起我的英语。当图片填满屏幕时,我想做的就是可以用来滚动。为此,请使用 ViewFlipper。但它不起作用。是全屏显示图像的类。我做错了什么?

    public class FullScreenImage extends Activity implements OnTouchListener{
private ViewFlipper flipper = null;
private float fromPosition;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_screen);
Intent intent = getIntent();
long imageId = intent.getExtras().getLong(FullScreenImage.class.getName());

LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main_layout);
flipper = (ViewFlipper) findViewById(R.id.fullImage);
flipper.setOnTouchListener(this);
ImageView imageView = (ImageView) findViewById(R.id.imageView1);

imageView.setLayoutParams( new ViewFlipper.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));

imageView.setImageResource((int) imageId);


}

public boolean onTouch(View view, MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
fromPosition = event.getX();
break;
case MotionEvent.ACTION_UP:
float toPosition = event.getX();
if (fromPosition > toPosition)
flipper.showNext();
else if (fromPosition < toPosition)
flipper.showPrevious();
default:
break;
}
return true;
}
}

xml文件

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

<ViewFlipper
android:id="@+id/fullImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</ViewFlipper>

</LinearLayout>

最佳答案

您的 XML 在脚蹼中只有一个成员。这个想法是有两个或项目,脚蹼将在它们之间改变。将这样的另一张图片添加到您的鳍状肢

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ViewFlipper
android:id="@+id/fullImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />


<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</ViewFlipper>

关于java - 不工作 ViewFlipper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26046907/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com