2011-10-05 106 views
0

我想讓我的自定義警報對話框滾動我的textview,我似乎無法得到它的工作。我有一個圖像和標題+關閉按鈕,然後滾動textview下面我有一個表內的三個按鈕。 任何人都可以弄清楚我做錯了什麼?滾動在自定義警報對話框中的TextView

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/layout_root" android:orientation="vertical" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:layout_marginLeft="10dip" android:layout_marginRight="10dip"> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relViewTitle" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:clickable="true"> 

    <ImageView android:id="@+id/titleImg" android:src="@drawable/redpin" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" /> 

    <TextView android:id="@+id/textTitle" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_toRightOf="@id/titleImg" 
     android:layout_marginTop="10dip" android:layout_marginLeft="30dip" 
     android:textColor="#fffafa" android:textStyle="bold" /> 

    <Button android:id="@+id/btnClose" android:text="Close" 
     android:layout_width="60dip" android:layout_height="35dip" 
     android:layout_alignParentRight="true" /> 
</RelativeLayout> 
    <View android:layout_width="fill_parent" android:layout_height="1dip" 
    android:background="#fffafa" /> 

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

    <TextView android:id="@+id/text" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:paddingLeft="20dip" 
     android:paddingRight="20dip" android:singleLine="false" 
     android:maxLines="7" android:scrollbars="vertical" 
     android:paddingBottom="20dip" android:textColor="#fffafa" /> 
    </ScrollView> 


    <TableLayout android:id="@+id/tableBtns" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:stretchColumns="*"> 

    <TableRow android:gravity="center" android:layout_width="wrap_content"> 
     <Button android:id="@+id/btnDialPrev" android:text="Previous" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" /> 
     <Button android:id="@+id/btnDialOk" android:text="ok" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" /> 

     <Button android:id="@+id/btnDialNext" android:text="Next" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" /> 
    </TableRow> 
    </TableLayout> 

+0

LinearLayout在哪裏結束? – Hiral

回答

1

它爲什麼要滾動?您已將maxLines設置爲7,並將高度設置爲wrap_content,因此它總是會佔用足夠的空間來顯示其所有內容。

+0

我認爲最大線會迫使它滾動在那個長度的線,我需要添加'android:fillViewport =「true」'來讓它工作。謝謝你的幫助。 –

+0

不,maxLines確實是最大的行;) – banzai86

+0

不,它的顯示高度參數:public void setMaxLines(int maxlines)從以下版本開始:API級別1 使TextView至多有很多行高。設置此值將覆蓋任何其他(最大)高度設置。 http://developer.android.com/reference/android/widget/TextView.html#setMaxLines%28int%29 – vmatyi

0

創建普通XML,並在想要使用新類顯示警報對話框時調用它。

alertbutton.setOnClickListener(新OnClickListener(){

public void onClick(View v) { 
     // TODO Auto-generated method stub 

     Intent i = new Intent(fromclassname.this, AlertDialog.class); 
     startActivity(i); 


    } 
}); 

------------------------------ -------------------------------------------------- -
呼叫從AlertDilog.class

的的your.XML

在最後的manifest.xml, 在活動聲明

機器人:名字=機器人:主題=「@ Android 」的AlertDilog。「 :style/Theme.Dialog「

相關問題