2013-09-24 16 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使用的字體大小