2015-07-06 30 views
0

每當在樣式xml表單上設置android:layout_gravity="bottom"屬性時,文本似乎在頂部被截斷,在底部出現額外的空行。我已經設置了這個功能,以便在顯示太多文本時自動滾動到底部。這是託管在DialogFragment設置layout_gravity時,ScrollView/TextView不顯示所有數據

注意:正在顯示的文本是從TextView.setText(Html.fromHtml())開始的,換行符是< br>(如果有的話)。 a的打印只是測試數據。

在調試TextView時,它顯示數據在那裏(在mText變量中),但它只是不顯示。

對話框XML表:

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

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:fillViewport="true" > 

     <TextView android:id="@+id/status_olcr_text" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" /> 

</ScrollView> 

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    style="?android:attr/buttonBarStyle" > 

    <Button 
     android:id="@+id/status_olcr_ok" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/ok" 
     style="?android:attr/buttonBarButtonStyle" 
     android:clickable="false" /> 

</LinearLayout> 

上正在發生什麼的屏幕顯示(但不應該):

Scrolling to the top (wrong)

Scrolling to the bottom (wrong)

這是應該發生什麼(當時ERE沒有layout_gravity屬性):

Scrolling to the top (correct)

Scrolling to the bottom (correct)

的發生了什麼你知道嗎?

更新:我已經打開「顯示佈局利潤率」和TextView的是滾動型邊界上方呈現(或周圍其他方法)。請參見下面的圖片:

Update: Scrolling to the top

Update: Scrolling to the bottom

+0

後綴xml with gravity set – Gordak

+0

爲什麼你要設置'gravit沒有設置'weight_sum'爲父。 –

+0

@Gordak不知道你的意思對不起,重力是標題'下設<:ID =「@ + ID/status_olcr_text」機器人:機器人的TextView = layout_gravity「底部」>' – marco9999

回答

0

結束了這個解決方案去,但我還是不明白擺在首位是怎麼回事...

中的相關DialogFragment:

scroll = (ScrollView)getView().findViewById(R.id.scroll); 
scroll.post(new Runnable() { 
    @Override 
    public void run() { 
     scroll.fullScroll(View.FOCUS_DOWN); 
    } 
}); 
0

我建議您使用RelativeLayout,您可以在其中將滾動視圖設置爲父級和按鈕行佈局頂部並將其設置爲底部。

<?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="match_parent"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/llButton" 
    android:alignParentTop="true" 
    android:fillViewport="true" > 

     <TextView android:id="@+id/status_olcr_text" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" /> 

</ScrollView> 

<LinearLayout 
    android:id="@+id/llButton" 
    android:alignParentBottom="true" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    style="?android:attr/buttonBarStyle" > 

    <Button 
     android:id="@+id/status_olcr_ok" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/ok" 
     style="?android:attr/buttonBarButtonStyle" 
     android:clickable="false" /> 

</RelativeLayout> 
+0

我已經嘗試了您的建議,但仍然無法運行。與問題中相同的問題。不管怎麼說,還是要謝謝你! – marco9999

0

內部的TextView Tag使用方法:

android:layout_gravity="top"