Android 用按钮和手指滑动图像
我正在尝试使用全屏模式显示的图像制作一个自定义图库,并能够使用上一个“下一步”按钮和手指在不同的图像之间滑动。因此,现在我使用手指更改图像,但是我不得不重新设计我的xml文件以及代码的整个结构和逻辑,我需要一些关于如何添加新内容的帮助或建议。因此,我用来用手指滑动图像的旧代码如下所示:Android 用按钮和手指滑动图像,android,image,gallery,fullscreen,swipe,Android,Image,Gallery,Fullscreen,Swipe,我正在尝试使用全屏模式显示的图像制作一个自定义图库,并能够使用上一个“下一步”按钮和手指在不同的图像之间滑动。因此,现在我使用手指更改图像,但是我不得不重新设计我的xml文件以及代码的整个结构和逻辑,我需要一些关于如何添加新内容的帮助或建议。因此,我用来用手指滑动图像的旧代码如下所示: this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.Layo
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
HorizontalPager realViewSwitcher = new HorizontalPager(getApplicationContext());
ImageView img1 = new ImageView(getApplicationContext());
ImageView img2 = new ImageView(getApplicationContext());
ImageView img3 = new ImageView(getApplicationContext());
ImageView img4 = new ImageView(getApplicationContext());
ImageView img5 = new ImageView(getApplicationContext());
ImageView img6 = new ImageView(getApplicationContext());
img1.setImageResource(R.drawable.one);
img2.setImageResource(R.drawable.two);
img3.setImageResource(R.drawable.three);
img4.setImageResource(R.drawable.four);
img5.setImageResource(R.drawable.five);
img6.setImageResource(R.drawable.six);
realViewSwitcher.addView(img1);
realViewSwitcher.addView(img2);
realViewSwitcher.addView(img3);
realViewSwitcher.addView(img4);
realViewSwitcher.addView(img5);
realViewSwitcher.addView(img6);
setContentView(realViewSwitcher);
这段代码以全屏模式显示图像,我可以在它们之间滑动。现在我需要这样做:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
HorizontalPager realViewSwitcher = new HorizontalPager(getApplicationContext());
ImageView img1 = new ImageView(getApplicationContext());
ImageView img2 = new ImageView(getApplicationContext());
ImageView img3 = new ImageView(getApplicationContext());
ImageView img4 = new ImageView(getApplicationContext());
ImageView img5 = new ImageView(getApplicationContext());
ImageView img6 = new ImageView(getApplicationContext());
img1.setImageResource(R.drawable.one);
img2.setImageResource(R.drawable.two);
img3.setImageResource(R.drawable.three);
img4.setImageResource(R.drawable.four);
img5.setImageResource(R.drawable.five);
img6.setImageResource(R.drawable.six);
realViewSwitcher.addView(img1);
realViewSwitcher.addView(img2);
realViewSwitcher.addView(img3);
realViewSwitcher.addView(img4);
realViewSwitcher.addView(img5);
realViewSwitcher.addView(img6);
setContentView(realViewSwitcher);
我希望能够用按钮和手指滑动图像。我的第二个问题是,如何在顶部(背面、加莱尔、信息)和底部(上一个、下一个)隐藏栏,并在全屏模式下显示图像,但仍然只能用手指滑动图像。
以下是我的xml文件的外观:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/single_card"
android:src="@drawable/one"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="@+id/actionbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal"
android:layout_gravity="center"
android:padding="10dp"
android:layout_alignParentTop="true" >
<Button
android:id="@+id/back_button"
android:text="Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#333333"
android:layout_centerVertical="true"
android:textSize="13dp"
android:textColor="#ffffff"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp" />
<TextView
android:text="Gallery"
android:textStyle="bold"
android:textSize="15dp"
android:textColor="#FFFFFF"
android:id="@+id/single_msg_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
<Button
android:id="@+id/info_button"
android:text="Info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#333333"
android:layout_centerVertical="true"
android:textSize="13dp"
android:textColor="#ffffff"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#000000" >
<Button
android:id="@+id/previous_button"
android:text="Previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#333333"
android:layout_alignParentLeft="true"
android:textSize="13dp"
android:textColor="#ffffff"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_marginLeft="50dp"
android:layout_marginBottom="10dp"
android:layout_alignParentBottom="true" />
<Button
android:id="@+id/next_button"
android:text="Next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#333333"
android:layout_alignParentRight="true"
android:textSize="13dp"
android:textColor="#ffffff"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="10dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</RelativeLayout>
提前感谢!!!欢迎提供任何帮助、建议或示例链接 不久前我做过类似的事情,基本上是用手指向左或向右滑动执行两种不同的操作,并且可以单击相同操作的按钮 在我的主要活动中,我注册了手指滑动侦听器:
gestureDetector = new GestureDetector(new ListItemGestureDetector(this));
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
然后,在呈现列表视图的高效适配器中,我注册按钮并单击它们(这对您来说不一样,但在将按钮添加到布局中时,我会这样做(呼叫和短信是布局中的按钮)
不久前我做过类似的事情,基本上是手指向左或向右滑动执行两种不同的操作,并且可以单击相同操作的按钮 在我的主要活动中,我注册了手指滑动侦听器:
gestureDetector = new GestureDetector(new ListItemGestureDetector(this));
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
然后,在呈现列表视图的高效适配器中,我注册按钮并单击它们(这对您来说不一样,但在将按钮添加到布局中时,我会这样做(呼叫和短信是布局中的按钮)
使用视图流项目来完成此操作。添加ImageView的代码根本不是一个好的解决方案
请参阅gitHub上的。还有图像示例。您所做的只是在“活动”中添加此布局,制作图像适配器,就这样。使用视图流项目来完成此操作。添加图像视图的代码根本不是一个好的解决方案
请参见gitHub上的。也有图像示例。您所做的只是在活动中添加此布局,制作图像适配器,就可以了。对于图像扫描,我们可以简单地使用ViewPager概念 1.在布局中设置viewpager
对于滑动图像,我们可以简单地使用ViewPager概念 1.在布局中设置viewpager
事实上,我不知道如何用你的代码更改我的代码,这样我才能让这些东西正常工作。在你的活动中,注册手势检测器。然后用按钮获取你的相对布局,并在其中在每个按钮上附加单击侦听器。事实上,我不知道如何用你的代码更改我的代码,这样我才能让这些东西正常工作工作。在活动中,注册手势检测器。然后获取包含按钮的相对布局,并在其中连接每个按钮上的单击侦听器。
public class MyMain extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
ImagePagerAdapter adapter = new ImagePagerAdapter();
viewPager.setAdapter(adapter);
}
private class ImagePagerAdapter extends PagerAdapter {
private int[] mImages = new int[] {
R.drawable.one,
R.drawable.two,
R.drawable.hree,
R.drawable.four
};
@Override
public int getCount() {
return mImages.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Context context = MyMain.this;
ImageView imageView = new ImageView(context);
int padding =context.getResources().
getDimensionPixelSize(R.dimen.padding_medium);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setImageResource(mImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
}