问题描述
我想使这个类型的横向滚动,看图片
I Want to make this type of horizontal scrolling , look at pictures
>>>> .......... ....................................
>>>>............................................
保存在RES /布局/ main.xml中的XML文件:我说的对我的main.xml文件worng?我想使用。
XML file saved at res/layout/main.xml:Am i right my main.xml file has worng? I want to use .
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/imageView1"
android:layout_width="wrap_content" android:layout_height="200dp"> </ImageView>
<TextView android:text="Zoo"
android:id="@+id/PicDescription" android:layout_width="wrap_content"
android:textSize="40sp" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_marginTop="10dp"></TextView>
<TextView android:text="Z" android:id="@+id/captitalText"
android:layout_height="wrap_content" android:layout_gravity="center" android:textSize="100sp"
android:layout_width="wrap_content" android:layout_marginTop="25dp"></TextView>
保存在RES /价值/ letters.xml XML文件:
<?xml version="1.0" encoding="utf-8"?>
resources>
<string-array name="desc">
<item>Apple</item>
<item>Ball</item>
...
<item>Zoo</item>
</string-array>
<string-array name="capitalLetter">
<item>A</item>
<item>B</item>
...
<item>Z</item>
</string-array>
什么是机器人的水平滚动操作的code。请大家给的意见,我是新android的,我完全糊涂了滚动。我按照这个link1 链接2 ,但不能得到任何想法。在此先感谢,并希望你能解决这个问题。
What is the code of that Horizontal scrolling action in android. Please give advice, I am the new of the android, I totally confused of that scrolling. I follow this link1 link2 but could not get any idea.Thanks in advance and hope you can solve this.
编辑:09月11日
下面是我的code.It出来的,当我尝试滚动然后改变B,当完成滚动再次成为网页。我想,我打电话的时候滚动完成初始值,对吗?
Here is my code.It out is when I try to scrolling then change B, when complete scrolling the page the again A becomes. I think, I call when scrolling is complete starting value, am i right?
给我建议,我能做些什么的修复此code。
Give me suggestion what can i do for fix this code.
public class Test extends Activity {
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private GestureDetector gestureDetector;
String[] big;
TextView txtbig;
int count=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
big = getResources().getStringArray(R.array.capitalLetter);
gestureDetector = new GestureDetector(new MyGestureDetector());
View mainview = (View) findViewById(R.id.mainView);
mainview.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
textChange();
return true;
}
return false;
}
});
//textChange();
}
private void textChange() {
txtbig = (TextView) findViewById(R.id.bigText);
String bigTextString=big[count];
txtbig.setText(bigTextString);
count++;
if(count==big.length)
{
count=0;
}
}
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
Intent intent = new Intent(Test.this.getBaseContext(),Test.class);
//textChange();
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
//textChange();
return false;
}
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { textChange();
startActivity(intent);
Test.this.overridePendingTransition(
R.anim.slide_in_right, R.anim.slide_out_left);
return true;
// right to left swipe
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
// startActivity(intent);
// textChange();
Test.this.overridePendingTransition(
R.anim.slide_in_left, R.anim.slide_out_right);
}
return false;
}
@Override
public boolean onDown(MotionEvent e) {
return true;
}
}
}
推荐答案
看看这个:
http://savagelook.com/blog/安卓/刷卡或 - 甩换导航功能于安卓
这篇关于如何使android的水平滚动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!