【问题标题】:turn on automatic scrollbar打开自动滚动条
【发布时间】:2014-03-28 16:09:56
【问题描述】:

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

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

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

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

这是我的布局

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

查看第三个编辑框,如果调用了这个活动资源,并且我的光标聚焦在第三个编辑框上,android 自动键盘出现并覆盖了我的第三个编辑框。屏幕应该自动拉起,让我知道我的光标在哪里,这样我就可以在框中输入,对吧?

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    把整个东西包起来:

    <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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-17
      • 1970-01-01
      • 2012-12-22
      相关资源
      最近更新 更多