2013-07-24 119 views
2

我刚刚在此FrameLayout中放入了一张非常大的图片,因为您可以看到这是一张地图。 我想将视图(按钮,ImageViews)放置在屏幕外,以便用户必须滚动才能在地图上“查找”它们。我使用这个地图上的左右滚动:Android: Scrolling an ImageviewAndroid - 在屏幕外放置视图

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/Container" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#000000" > 

    <ImageView 
     android:id="@+id/map" 
     android:layout_width="2500dp" 
     android:layout_height="2000dp" 
     android:src="@drawable/map" /> 
</FrameLayout> 

当我尝试以编程方式添加一个按钮或只是把它在XML中,只有当它的利润率左和边距位置显示与屏幕的尺寸相关。 (我相信480乘800)。 如果我添加例如视图不会显示的这些尺寸之外的按钮,即使朝向它滚动时也不会显示。 FrameLayout margin not working解决方案也不起作用。

添加这个工程:

<Button 
     android:id="@+id/one" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/one" 
     android:layout_marginLeft="420px" 
     android:layout_marginTop="240px" 
     android:layout_gravity="top" 
     android:onClick="click" /> 

修改它这样,它不会显示了,甚至走向它滚动时:

<Button 
     android:id="@+id/one" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/one" 
     android:layout_marginLeft="1290px" 
     android:layout_marginTop="940px" 
     android:layout_gravity="top" 
     android:onClick="click" /> 

如果我使用像素或DP不要紧,该视图根本没有显示。

我不知道这是为什么,但我很乐意听到解决方案。任何帮助表示赞赏。

回答

1

现在不能正常工作的原因是因为当使用fill_parent时,您的FragmeLayout宽度和高度太小,而您试图将按钮添加到已经结束的位置。

而且你真的在使用解决方案Android: Scrolling an Imageview只是设置ImageView的新滚动位置(你不滚动FragmeLayout本身)。

问题的解决方案是将父母的layout_width和layout_height设置为ImageView的宽度和高度,并将onLouchListener从Android: Scrolling an Imageview用于整个FrameLayout。

+0

啊,我忘了提及我有FrameLayout上的滚动,但我会尝试通过设置宽度和高度来解决您的问题。这可能确实起作用! – Gooey

相关问题