我需要在Android中创建一个视图,涉及将可变数量的图像放置在屏幕上的特定位置。我的问题是,这个位置不应该根据屏幕的大小而变化。另外,它的位置必须相对于背景图像。 例如,我有一个房子的形象,我必须通过一些固定的坐标来安排窗户和门。 建议?在屏幕上的特定位置imageView
0
A
回答
1
除了对如何检测MotionEvents,将以下方法添加到LayeredImageView您的评论:
public List<Layer> getLayersAt(float x, float y) {
Iterator<Layer> iter = mLayers.iterator();
List<Layer> list = new LinkedList<Layer>();
RectF rect = new RectF();
Matrix m = getImageMatrix();
while (iter.hasNext()) {
Layer layer = iter.next();
rect.set(layer.drawable.getBounds());
layer.matrix.mapRect(rect);
m.mapRect(rect);
if (rect.contains(x, y)) {
list.add(layer);
}
}
return list;
}
你可以这样称呼它:
public boolean onTouch(View v, MotionEvent event) {
float x = event.getX();
float y = event.getY();
List<Layer> list = iv.getLayersAt(x, y);
}
0
您可以对您的LinearLayout使用android:weightSum属性,然后根据权重数字将LinearLayout上的视图与android:layout_weight分开。我在这里有一个例子:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="70"
android:gravity="bottom|center_horizontal"
android:orientation="horizontal"
android:weightSum="100" >
<ImageView
android:id="@+id/ivHamsa"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="50"
android:scaleType="fitCenter"
android:src="@drawable/hamsa_icon" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="20"
android:gravity="top|center_horizontal"
android:orientation="horizontal"
android:weightSum="100" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="70"
android:gravity="top|center_horizontal"
android:orientation="horizontal"
android:weightSum="100" >
<ImageView
android:id="@+id/ivAndroid"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20"
android:scaleType="fitCenter"
android:background="@drawable/rounded_white"
android:layout_margin="5dp"
android:src="@drawable/android_icon" />
<ImageView
android:id="@+id/ivBook"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20"
android:scaleType="fitCenter"
android:background="@drawable/rounded_white"
android:layout_margin="5dp"
android:src="@drawable/book_icon" />
<ImageView
android:id="@+id/ivMusic"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20"
android:scaleType="fitCenter"
android:background="@drawable/rounded_white"
android:layout_margin="5dp"
android:src="@drawable/music_icon" />
<ImageView
android:id="@+id/ivVideo"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20"
android:scaleType="fitCenter"
android:background="@drawable/rounded_white"
android:layout_margin="5dp"
android:src="@drawable/video_icon" />
<ImageView
android:id="@+id/ivPhoto"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20"
android:scaleType="fitCenter"
android:background="@drawable/rounded_white"
android:layout_margin="5dp"
android:src="@drawable/photo_icon" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:orientation="horizontal" >
</LinearLayout>
相关问题
- 1. 在特定屏幕位置的图像
- 2. 在setOnClickListener上设置imageView全屏幕
- 3. 单击特定位置上的ImageView
- 4. 如何在屏幕上的特定位置显示MessageBox
- 5. 如何在每个屏幕上查找特定位置?
- 6. Android:我如何定位列表视图在屏幕上的特定位置
- 7. 在屏幕上设置TableView的位置
- 8. 屏幕上的位置div处于特定形状
- 9. 在屏幕的特定位置绘制自定义视图 - Android
- 10. 在不同屏幕上定位位图
- 11. PowerPoint VBA - SlideRange在屏幕上的位置
- 12. 在不同屏幕上的div位置
- 13. 在新位置上的屏幕
- 14. 鼠标在屏幕上的Java位置
- 15. 在屏幕上查找行的位置
- 16. ButtonClick - >在新屏幕上的ImageView?
- 17. Python:如何在python的特定位置点击屏幕,MAC OS
- 18. 在屏幕上方隐藏ImageView /以编程方式设置y位置为负
- 19. 在屏幕上的特定坐标上设置TextView
- 20. 将ImageView设置在屏幕中央
- 21. 在Android上获取主屏幕位置
- 22. 位置在黑莓屏幕上点击
- 23. 在主屏幕上获取appwidget位置?
- 24. 在屏幕上获取按钮位置
- 25. 忙光标位置在屏幕上
- 26. 在屏幕上的特定位置打印彩色文本的ASM子程序
- 27. 如何在ImageView上的特定位置显示文本?
- 28. 在NSTextView中的位置屏幕上的位置
- 29. Java ImageView没有出现在屏幕上
- 30. LinearLayout imageview不适合在屏幕上?
请参阅我对此问题的回答http://stackoverflow.com/questions/16729169/how-to-maintain-multi-layers-of-imageviews-and-keep-their-aspect-ratio-based-on – pskink
正是我所期待的,但我需要能够点击添加到主图层的每个元素。 – user1169390
看到注释掉石灰 – pskink