在滚动视图下方对齐文本视图

时间:2015-11-01 13:34:50

标签: android android-layout

我使用以下布局层次结构:
的LinearLayout
....的LinearLayout
....... TextView
.... RelativeLayout的
.......... TextView的
....滚动型
....放在我想要固定底部文本视图的地方

我在SO上阅读 - 我需要在ScrollView中输入以下属性:

android:layout_weight="1"  

这确保了我的底部文本视图(打算修复)。

所以虽然这有效 - 但问题是 - 如果我的滚动视图中的内容较少(内容会动态填充) - 底部的文本视图会爬上去,让它看起来很难看。

我想要的是修复底部视图 - 无论滚动视图的内容如何。

这是我的布局:

    <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
        <LinearLayout style="@style/ExamTitleBar" >

        <ImageButton
            android:id="@+id/imgPrevious"
            style="@style/TitleBarAction"
            android:contentDescription="@string/description_home"
            android:onClick="previous"
            android:src="@drawable/previous" />

         <ImageButton
            android:id="@+id/imgHome"
            style="@style/TitleBarAction"
            android:contentDescription="@string/description_home"
            android:onClick="onClickHome"
            android:src="@drawable/title_home" />

        <ImageView style="@style/TitleBarSeparator" />

        <TextView style="@style/ExamTitleBarText" />

        <ImageView style="@style/TitleBarSeparator" />


        <ImageButton
            android:id="@+id/imgNext"
            style="@style/TitleBarAction"
            android:contentDescription="@string/description_search"
            android:onClick="next"
            android:src="@drawable/next" />

        <ImageButton
            android:id="@+id/imgReport"
            style="@style/TitleBarAction"
            android:contentDescription="@string/description_search"
            android:onClick="reportDisplay"
            android:src="@drawable/setttings" />
    </LinearLayout>


    <RelativeLayout style="@style/MessageBar" >

        <TextView
            android:id="@+id/msgBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/questionCount"
            android:layout_alignParentLeft="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:layout_marginLeft="7dip" />

        <TextView
            android:id="@+id/timeLeft"
            android:layout_alignParentRight="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </RelativeLayout>


     <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/questionlabel"
         android:layout_weight="1">


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

        <TextView
            android:id="@+id/Question"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:layout_marginLeft="7dip"
            android:layout_marginRight="5dip"
            android:layout_marginTop="5dip"
            android:layout_marginBottom="5dip"
            android:fontFamily="Helvetica"
            android:textSize="17sp"/>



        <LinearLayout style="@style/SeparatorBarTop" >

            <TextView
                android:id="@+id/separatorBar1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>



        <RadioGroup 
            android:id="@+id/radiogroup"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" 
             android:fontFamily="Helvetica"
            android:textSize="17sp"
            >

            <RadioButton style="@style/RadioButtons"
                android:id="@+id/option1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Option1" />

            <RadioButton style="@style/RadioButtons"
                android:id="@+id/option2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Option2" />

            <RadioButton style="@style/RadioButtons"
                android:id="@+id/option3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Option3" 
                />

            <RadioButton style="@style/RadioButtons"
                android:id="@+id/option4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Option4" />
        </RadioGroup>



        <LinearLayout style="@style/SeparatorBarBottom" >

            <TextView
                android:id="@+id/separatorBar2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>

        <!-- image view goes here start -->
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:src="@drawable/velocity_graph" />
        <!-- image view goes here end -->

        <TextView style="@style/AnswerDetails"
            android:id="@+id/AnswerDetails"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:layout_marginLeft="5dip"
            android:layout_marginRight="7dip"
            android:layout_marginTop="5dip" 
            android:fontFamily="Helvetica"
            android:textSize="17sp"/>



        <!-- separator bar for image start
        <LinearLayout style="@style/SeparatorBarBottom" >

            <TextView
                android:id="@+id/separatorImageBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
        separator for for image end -->

    </LinearLayout>
    </ScrollView>

    <!-- desired fixed bottom view -->
    <LinearLayout  android:layout_gravity="bottom" style="@style/ExamTitleBar" >
        <TextView style="@style/ExamTitleBarText" />
    </LinearLayout>
     <!-- moiraine end -->





</LinearLayout>

2 个答案:

答案 0 :(得分:0)

将ScrollView高度设置为固定大小。例如。 String[] studentRoster = { "1,John,Smith,John1989@gmail.com,20,88,79,59", "2,Suzan,Erickson,Erickson_1990@gmailcom,19,91,72,85", "3,Jack,Napoli,The_lawyer99yahoo.com,19,85,84,87", "4,Erin,Black,Erin.black@comcast.net,22,91,98,82", "5,Adan,Ramirez,networkturtle66@gmail.com,24,100,100,100" }; for (int k = 0; k < studentRoster.length; k++) { String s2 = studentRoster[k]; String [] parts2 = s2.split(","); String Email2 = parts2[3]; String invemail2 = Email2; boolean emailfound = false; boolean emailfound2 = false; boolean enotfound; boolean enotfound2; for (int i = 0; i < invemail2.length(); i++) { char emailfind = invemail2.charAt(i); if (emailfind == '@') { emailfound = true; } else { enotfound = false; } if (emailfind == '.') { emailfound2 = true; } else { enotfound2 = false; } } if (emailfound && emailfound2) { System.out.println(invemail2 + " " + "is a valid email"); } else { System.out.println(invemail2 + "is invalid"); } } 。一个包含所有组件的RelativeLayout就足够了,使用alignBottom。嵌套布局会降低您的应用效果,请参阅开发文档:http://developer.android.com/training/improving-layouts/optimizing-layout.html

答案 1 :(得分:0)

1.最后Linearlayout应该有一个固定的高度;

2.很多样式,plz在布局中放置布局attr;

3. RelativeLayout在这种情况下更好;

4.当android:orientation="vertical"时,android:layout_gravity="bottom"无效