【发布时间】:2012-11-09 11:02:06
【问题描述】:
我是 Android 编程新手,现在我正在尝试将图像放置在水平滚动视图中。
实际上我想要做的是,我想显示需要从右到左自动滚动的图像数组。
到目前为止,我已经尝试如下
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/image2"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@drawable/icon"
android:layout_centerHorizontal="true"
android:layout_marginRight="5px"/>
</LinearLayout>
</HorizontalScroll>
活动文件-
package com.myhorizontalScroll;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;
public class MyHorizontalScrollActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// declare a class field:
final Handler h = new Handler();
// later:
final ImageView scroll=(ImageView)findViewById(R.id.image2);
Thread t = new Thread(){
public void run(){
int y = scroll.getScrollY();
int x = scroll.getScrollX();
while(y<1600){
// need final values to create anonymous inner class
final int X = x;
final int Y = y;
h.post(new Runnable() {
public void run() {
scroll.scrollTo(X, Y);
}
});
x++;
try {
sleep(1000/12);
} catch (InterruptedException e) {
}
}
}
};
t.start();
}
}
现在图像视图从左到左; imageview 实际位于左侧。
如何将图像视图放在右侧,我希望这种滚动需要连续完成。
我该怎么做?
【问题讨论】:
-
那么,有什么问题?
-
您是经验丰富的 stackoverflow 用户,为什么这个问题的标题很烂?将其更改为:“如何制作图像选取框”或类似内容(我现在不能这样做 - 其他一些编辑正在等待中)。
-
@user198725878:不要在问题标题中包含标签详细信息。在发布问题之前,请阅读stackoverflow.com/faq
标签: android scroll imageview horizontal-scrolling