【问题标题】:ScrollView with fixed height inside dialog in AndroidAndroid中对话框内具有固定高度的ScrollView
【发布时间】:2013-09-24 12:06:54
【问题描述】:

我正在尝试使用此代码在对话框弹出窗口中执行 ScrollView:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="40dp" >

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="40sp"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/new_realm_avatar"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_centerHorizontal="true"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/new_realm_message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/new_realm_avatar"
            android:text="long text" />
    </RelativeLayout>
 </ScrollView>

</RelativeLayout>

因此,当我在消息部分中调用它并且文本大于屏幕时,它变得可滚动但隐藏了键并且它的高度与手机屏幕一样大。我希望对话框中的消息具有固定的高度,就像我尝试用另一个布局包装 ScrollView 并强制它的高度一样,但它也不起作用。那么有人有什么想法吗?

【问题讨论】:

    标签: android xml android-layout android-scrollview scrollable


    【解决方案1】:

    试试这个

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="40dp" >
    
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="40dp" >
    
            <ImageView
                android:id="@+id/new_realm_avatar"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_centerHorizontal="true"
                android:src="@drawable/ic_launcher" />
    
            <TextView
                android:id="@+id/new_realm_message"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/new_realm_avatar"
                android:text="long text" />
        </RelativeLayout>
    </ScrollView>
    
    </RelativeLayout>
    

    【讨论】:

    • 它帮助了我。谢谢!你能解释一下这背后的原因吗?
    【解决方案2】:

    首先在你的孩子RelativeLayout替换这个:

    android:layout_height="40sp"
    

    android:layout_height="40dp"
    

    因为sp 用于字体大小

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      • 1970-01-01
      • 1970-01-01
      • 2015-06-01
      • 1970-01-01
      相关资源
      最近更新 更多