【发布时间】:2013-07-11 15:22:29
【问题描述】:
我在使用 ScrollView 和 ImageView 时遇到了一些问题。
我想要的是:
我在屏幕顶部始终设置了一个ImageView。然后,我有一个ScrollView,其中包含View 的所有元素,在其中我有另一个ImageView,当前面的元素没有填满屏幕(通常是大屏幕)时,它设置在屏幕底部, 并且在存在 Scroll 时设置在ScrollView 的底部。
我有其他一些Activities 没问题,但是我在一个有FrameLayout 的Activity 中遇到了一些问题。
我得到的是:
(见下面的代码)当我在RelativeLayout 中设置ImageView 时(留在底部的那个)height = "wrap_content":
- 纵向:
Image没有实际尺寸,因为它不适合屏幕。为了适应它,Scroll应该出现。 -> 我不知道为什么它不像其他Activities那样出现。 - 横向:
ImageView出现在屏幕底部。由于其他元素无法在屏幕上显示,Scroll会出现在FrameLayout中。
当我设置在ImageView 的RelativeLayout 中时(留在底部的那个)height = "200dp"(图像的实际高度更小):
- 纵向:
Image不出现。没有任何Scroll(没有必要,因为可以看到其他元素)。 - 横向:出现两个
Scrolls。一个在FrameLayout中用于元素,另一个用于查看ImageView。
这是我的最新代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
tools:context=".FacturasActivity"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayoutLogoFactor_factura"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<ImageView
android:id="@+id/imageViewLogoFactor_factura"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo_factorenergia"/>
</LinearLayout>
<ScrollView
android:id="@+id/scrollViewMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:id="@+id/linearLayoutMain2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_gravity="center_horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayoutDireccionFactura"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="10dp"
android:weightSum="1.0">
<TextView
android:id="@+id/textViewlabelDireccionFactura"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="@string/etiqueta_direccion"
android:textSize="@dimen/textSize"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewDireccion"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:textSize="@dimen/textSize" />
</LinearLayout>
<FrameLayout
android:id="@+id/frameLayoutFacturas"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="10dp" >
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/facturas_vacia"
android:textSize="@dimen/textSize" />
</FrameLayout>
<RelativeLayout
android:id="@+id/linearLayoutImagenInferior_main"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" >
<ImageView
android:id="@+id/imageViewImagenInferior_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="@drawable/la_electrica_de_las_empresas" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
你能帮帮我吗?提前致谢。
【问题讨论】:
-
我不明白你在说什么?但是,我认为您对 ScrollView 中的 ListView 有问题,因为它们都包含默认的滚动功能。因此,您既可以在横向模式下滚动,也可以在平滑滚动中遇到问题。我说的对吗?
-
是的,并且在某些情况下看不到
ImageView。可能是因为ListView在ScrollView中的问题? -
您的触摸会考虑执行哪个滚动,但是当您有不同的空间时。在您的情况下,ListView 和 ScrollView 在小屏幕设备中占用相同的空间。所以,它不会检测到滚动视图滚动,所以它执行 ListView 滚动。并且你的底部图像隐藏在底部区域。
-
对于滚动管理检查this问题对你有用。
-
我不想同时滚动,但我在评论中的建议问题中找到了我的解决方案。现在只有一个卷轴,
ScrollView的卷轴,就像我想要的那样。再次非常感谢!
标签: android imageview scrollview android-framelayout