【问题标题】:Unable to scroll无法滚动
【发布时间】:2012-07-27 05:58:58
【问题描述】:

请查看以下负责创建 GUI 的 android xml 文件

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/imageTitle"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="14dp"
        android:text="@string/imageDate"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="254dp"
        android:layout_weight="0.34"
        android:src="@drawable/test_image" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="fill_parent"
        android:layout_height="136dp"
        android:text="@string/imageDescription" />

</LinearLayout>
</ScrollView>

我正在尝试滚动整个屏幕,但没有发生。上传的图片会让您一目了然。为什么它不滚动?我是 android 新手,这是我的第二个应用程序。请帮忙!

【问题讨论】:

  • 使用 wrap_content 作为您的 LinearLayout
  • 实际上它需要 wrap_content 即使我们给了 fill_parent 我猜。因为在我的应用程序中,当我使用 fill_parent 时,它会要求将其设为 wrap_content,而我没有,但它仍然可以正常工作

标签: java android eclipse android-layout android-emulator


【解决方案1】:

对于使用滚动视图,如果你有整个视图可滚动,使用滚动视图作为父布局并使用这样的代码。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">

这里android:fillViewport="true" 这是重要的部分,它允许你为你的布局填满整个屏幕。如果有任何其他问题问。

正如 android.developer 所说的 fillViewport Defines whether the scrollview should stretch its content to fill the viewport.

【讨论】:

    【解决方案2】:

    把这2改成这样

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >  
    
    
    <TextView
         android:id="@+id/textView3"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="@string/imageDescription" />
    

    【讨论】:

      【解决方案3】:

      我认为你应该在 LinearLayout 中使用 wrap_content

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-30
        • 2021-03-23
        • 2019-02-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多