2013-09-24 19 views
1

我试图做滚动型对话框弹出,此代码里面对话框固定高度:滚动型与Android的

<?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并强制执行它的高度一样,但它不能以这种方式工作。所以任何人有任何想法?

回答

3

试试这个

<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> 
+0

它帮助 我。谢谢!你能解释我背后的原因吗? –

1

首先在你的孩子的RelativeLayout替换此:

android:layout_height="40sp" 

android:layout_height="40dp" 

因为sp使用的字体大小