2016-12-04 142 views
1

因此,我有一個線性佈局和一個textview(都包含在scrollview中)。我想在最初的屏幕底部放置文本視圖(我不希望它被固定在底部)。我跟着這個問題Adding view to bottom of layout inside a scrollview 但它沒有幫助。這是我的佈局。 (所有layout_width屬性都是match_parent)將視圖添加到滾動視圖的底部佈局

<ScrollView 
android:layout_height="match_parent" 
android:fillViewport="true"> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
     android:layout_height="0dp" 
     android:layout_weight="1"> 
     <!-- this expands to fill the empty space if needed --> 
    </LinearLayout> 

    <!-- this sits at the bottom of the ScrollView, 
    getting pushed out of view if the ScrollView's 
    content is tall enough --> 
    <TextView 
     android:layout_height="wrap_content" 
     android:text="something"> 
    </TextView> 
</LinearLayout> 
</ScrollView> 

問題是textview永遠不可見。你能告訴我可以做些什麼來解決它嗎? (最初有足夠的空間讓線性佈局和textview適合屏幕) PS:請不要標記爲重複,因爲所有其他相關問題都希望textview在底部固定。

+0

哪一部分該屏幕的你期望滾動,如果最後一個項目是TextView的,如果放置在底部? – foxanna

+0

我需要整個屏幕滾動。我在線性佈局編輯文本,當我點擊它們時,軟鍵盤打開,因此我需要滾動屏幕。文本視圖應該只在底部初始化 – Jacksparrow

+0

從Activity.java文件中的佈局文件膨脹視圖,並嘗試在滾動視圖上使用addView方法。不知道是否 – Asym

回答

1

試試這個

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="10" 
     android:fillViewport="true"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="something"> 
      </TextView> 
     </LinearLayout> 

    </ScrollView> 

    <include 
     layout="@layout/your_edit_text_layout_here" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="bottom" /> 
</LinearLayout> 
+0

這也行不通 – Jacksparrow

+0

副本這個anwser ... http://stackoverflow.com/a/4258531/3678308 ... –

+0

更新了代碼嘗試上面的一個,可能會填寫您的要求。 –

0

嘗試this.It可以解決你的問題

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 


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

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 


       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="text1" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="text2" /> 


      </LinearLayout> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="something"></TextView> 
     </LinearLayout> 

    </ScrollView> 
</RelativeLayout> 
相關問題