打开自动滚动条

时间:2014-03-28 16:09:57

标签: android android-layout

我有一个包含tablelayout和相对布局的线性布局

相对布局设置为页脚 在表格布局中,我定位了其他几个组件(文本视图,编辑框,按钮)

我希望这个表格布局有滚动条

我将其属性设置为已经有一个垂直滚动条但它不起作用

这是我的布局

<LinearLayout xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:scrollbarStyle="insideOverlay"
    android:scrollbars="vertical"
    tools:context="com.teo.cuteoeditor.PreferenceActivity$PlaceholderFragment" xmlns:android="http://schemas.android.com/apk/res/android">

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbarStyle="insideOverlay"
        android:scrollbars="vertical" >

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp" >

            <include
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                layout="@layout/pref_title_layout"
                android:scrollbarStyle="insideOverlay"
                android:scrollbars="vertical" />

            </TableRow>

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="1px"
            android:background="#42424242" />

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp" >

            <include
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                layout="@layout/pref_desc_layout"
                android:scrollbars="vertical" />

            </TableRow>
        <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="1px"
        android:background="#42424242" />

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp" >

            <include
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                layout="@layout/pref_location_layout"
                android:scrollbarStyle="insideOverlay" />

            </TableRow>
        <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="1px"
        android:background="#42424242" />

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp" >

            <include 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                layout="@layout/pref_time_to_from" />
        </TableRow>
        <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="1px"
        android:background="#42424242" />

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp" >

            <include 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                layout="@layout/pref_reminder" />
        </TableRow>
    </TableLayout>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="1px"
        android:background="#42424242" />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom|center_vertical|center_horizontal" >

        <Button
            android:id="@+id/pref_save_btn"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="100dp"
            android:layout_height="35dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_centerInParent="false"
            android:text="@string/pref_cancel" />

        <Button
            android:id="@+id/pref_cancel_btn"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="100dp"
            android:layout_height="35dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="false"
            android:layout_centerInParent="false"
            android:layout_centerVertical="false"
            android:layout_marginRight="10dp"
            android:text="@string/pref_save" />

    </RelativeLayout>

</LinearLayout>

查看3个编辑框,如果调用此活动资源,并且我的光标聚焦于第三个编辑框,则会显示android自动键盘并覆盖我的第3个编辑框。屏幕应该拉起来让我知道我的光标在哪里,我可以在框中输入,对吧?

1 个答案:

答案 0 :(得分:0)

将整个事情包括在内:

<ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scrollbars="none"
        android:layout_weight="1">
        <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical">


       </LinearLayout>
     </ScrollView>

另请查看:: How to scroll table layout in horizontal and vertical in android