2012-01-24 184 views
0

我想添加一個自定義對話框,但我必須創建一個XML的問題,像我想..自定義對話框XML

這裏是我想象:

[IMAGE] [TEXT]

[ SCROLLABLETEXT]

[按鈕] [按鈕] [BUTTON]

而且我目前的xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/imgMentor" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:src="@drawable/changelogicon" /> 

     <TextView 
      android:id="@+id/tvSubject" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="--" 
      android:textColor="#FFF" 
      android:textSize="20px" /> 
    </LinearLayout> 

    <ScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/layout_root" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:padding="10dp" > 

     <TextView 
      android:id="@+id/tvExplanation" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="7dip" 
      android:text="--" 
      android:textColor="#FFF" /> 
    </ScrollView> 

    <LinearLayout 
    android:id="@+id/linearLayout2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:baselineAligned="true" > 


    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Button" /> 


    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Button" /> 


    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Button" /> 

</LinearLayout> 

</LinearLayout> 

圖片,文本和滾動文本看起來棒極了,但如果在中間的文字變得太長而變得滾動,我的按鈕都不見了..

我做了什麼錯?

編輯: 我的解決方案:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/imgIcon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:src="@drawable/changelogicon" /> 

    <TextView 
     android:id="@+id/tvSubject" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/imgIcon" 
     android:layout_marginBottom="15dp" 
     android:layout_toRightOf="@+id/imgIcon" 
     android:text="--" 
     android:textColor="#FFF" 
     android:textSize="20px" /> 

    <ScrollView 
     android:id="@+id/layout_root" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/button1" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/imgIcon" 
     android:layout_marginTop="20dp" > 

     <TextView 
      android:id="@+id/tvExplanation" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="7dip" 
      android:text="--" 
      android:textColor="#FFF" /> 
    </ScrollView> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:text="Button" /> 

</RelativeLayout> 
+0

試圖把scrollview放在你的主要線性佈局之外。 – Hiral

回答

1

使用RelativeLayout而非LinearLayout在視圖層次結構中的頂級元素。 LinearLayout在處理這種「填滿中間」情況時做得不太好。

使用RelativeLayout您可以將按鈕與底部對齊,將文本/圖像與頂部對齊,然後將您的ScrollView對齊到文本/圖像下方和按鈕上方,從而相應地拉伸它。

查看"Hello RelativeLayout"教程獲取更多信息。

快速提示:如果您提高接受率,更多人可能會回答您的問題。

+0

完美,非常感謝! :) – Prexx