将视图添加到滚动视图的底部布局

问题描述:

因此,我有一个线性布局和一个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

试试这个

<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

更新了代码尝试上面的一个,可能会填写您的要求。 –

尝试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>