在我的应用程序中,我想放置一个.png文件,我希望它在横向和纵向模式下均可作为滚动图像进行查看,请提供代码或示例....在android中的滚动视图中的图像
1
A
回答
3
一个简单的解决方案是将滚动它含有比容器大得多的ImageView的容器:
<?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="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/Container"
android:layout_width="200dp"
android:layout_height="200dp" >
<ImageView
android:id="@+id/ImageView01"
android:layout_width="480dp"
android:layout_height="800dp"
android:src="@drawable/sky_bgr" >
</ImageView>
</LinearLayout>
</LinearLayout>
然后使用代码来滚动它:
public class StartActivity extends Activity {
private LinearLayout container;
private int currentX;
private int currentY;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
container = (LinearLayout) findViewById(R.id.Container);
container.scrollTo(220, 400);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
currentX = (int) event.getRawX();
currentY = (int) event.getRawY();
break;
}
case MotionEvent.ACTION_MOVE: {
int x2 = (int) event.getRawX();
int y2 = (int) event.getRawY();
container.scrollBy(currentX - x2 , currentY - y2);
currentX = x2;
currentY = y2;
break;
}
case MotionEvent.ACTION_UP: {
break;
}
}
return true;
}
}
这里许多改进可制成如限制滚动范围等等 另一种方式是控制的ImageView矩阵... 然后你就可以将图像加载到一个位图,并在画布上绘制等它的一部分
-2
试试这个:
<ScrollView>
<HorizontalScrollView>
<ImageView/>
</HorizontalScrollView>
</ScrollView>
3
为了让您的ImageView滚动,如果它不适合的高度,你可以在旁边的XML滚动型内的ImageView,&加这个参数 -
android:adjustViewBounds="true"
下面是一个例子 -
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@drawable/back" >
</ImageView>
</ScrollView>
相关问题
- 1. Android:滚动图像视图
- 2. 无限滚动滚动视图中的图像android
- 3. Xcode:滚动视图与滚动视图中的图像
- 4. 滚动视图中的图像
- 5. 如何在android中获取图像的水平滚动视图?
- 6. 在滚动视图中插入图像
- 7. 在滚动视图中显示图像
- 8. 在滚动视图中缩放图像
- 9. 在滚动视图中的EditText在android
- 10. 在滚动时跟踪滚动视图中图像的位置
- 11. 在android中滚动视图中剪裁背景图像
- 12. 如何从滚动视图中的图像中间滚动?
- 13. 从滚动视图中拖动图像
- 14. 在滚动视图中的Android GridView
- 15. 在android sdk中的可滚动视图
- 16. 滚动视图内滚动视图android
- 17. 更改滚动视图在android的滚动视图的颜色
- 18. Android中的可滚动滑动视图
- 19. 在android中滚动到中间的滚动视图
- 20. 如何防止滚动视图中的图像滚动?
- 21. 无法在swift中使用滚动视图滚动图像
- 22. 滚动视图与图像不滚动
- 23. Android获取视图在水平滚动视图中的位置
- 24. 在android中的滚动视图回收视图
- 25. 创建动态视图,而像在Instagram中滚动视图
- 26. 在滚动视图中的Webview滚动整个视图
- 27. 自动滚动:如何在滚动视图中自动滚动图像
- 28. Android中的圆形滚动视图
- 29. 滚动视图和图像视图
- 30. Android滚动视图
理论上好主意,但一个滚动阻止另一个 - 你不能同时在2.2上同时滚动x和y – Lumis 2011-02-14 13:26:13