【问题标题】:Unable to Scroll Linear Layout by ScrollView tag无法通过 ScrollView 标签滚动线性布局
【发布时间】:2014-04-22 16:36:16
【问题描述】:

我的活动有以下 xml 文件,我已经让它可以滚动但我无法滚动它

<FrameLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.first.MainActivity"
    tools:ignore="MergeRootFrame" >

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


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

        <TextView
            android:id="@+id/textView1"
            android:layout_width="332dp"
            android:layout_height="wrap_content"
            android:text="@string/main_label"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/name_hint"
            android:inputType="textPersonName" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/address"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/address_hint" />

        <EditText
            android:id="@+id/phone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/phone_hint"
            android:inputType="phone" />

        <EditText
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/email_hint"
            android:inputType="textEmailAddress" />

        <EditText
            android:id="@+id/date"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/dob_hint"
            android:inputType="date" />

        <TextView
            android:id="@+id/martial_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/marrital_label"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/m_radio" />

        <RadioButton
            android:id="@+id/radioButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/um_radio" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hobby_label"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <CheckBox
                android:id="@+id/checkBox1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/h_cricket" />

            <CheckBox
                android:id="@+id/checkBox2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/h_bookreading" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <CheckBox
                android:id="@+id/checkBox3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/h_programming" />

            <CheckBox
                android:id="@+id/checkBox4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/h_gardening" />
        </LinearLayout>

        <CheckBox
            android:id="@+id/checkBox5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/h_football" />

        <Button
            android:id="@+id/next1"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="@string/b1_text" />
    </LinearLayout>

</FrameLayout>

【问题讨论】:

    标签: android scrollview android-linearlayout


    【解决方案1】:

    仅供参考,FrameLayout 旨在阻止屏幕上的一个区域以显示单个项目。

    因此,如果您希望滚动内容,请使用任何其他布局,而不是 Framelayout。

    【讨论】:

    • 对不起,我已经更新了问题...查看编辑,它不起作用
    • @Ahmed,您编辑的问题没有结束标记
    【解决方案2】:

    你需要在 scrollView 中包含 LinearLayout,像这样:

    <FrameLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.first.MainActivity"
    tools:ignore="MergeRootFrame" >
    
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:isScrollContainer="true"
        android:orientation="vertical" >
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="332dp"
            android:layout_height="wrap_content"
            android:text="@string/main_label"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    
        <EditText
            android:id="@+id/name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/name_hint"
            android:inputType="textPersonName" >
    
            <requestFocus />
        </EditText>
    
        <EditText
            android:id="@+id/address"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/address_hint" />
    
        <EditText
            android:id="@+id/phone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/phone_hint"
            android:inputType="phone" />
    
        <EditText
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/email_hint"
            android:inputType="textEmailAddress" />
    
        <EditText
            android:id="@+id/date"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/dob_hint"
            android:inputType="date" />
    
        <TextView
            android:id="@+id/martial_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/marrital_label"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    
        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/m_radio" />
    
        <RadioButton
            android:id="@+id/radioButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/um_radio" />
    
        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hobby_label"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
    
            <CheckBox
                android:id="@+id/checkBox1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/h_cricket" />
    
            <CheckBox
                android:id="@+id/checkBox2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/h_bookreading" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
    
            <CheckBox
                android:id="@+id/checkBox3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/h_programming" />
    
            <CheckBox
                android:id="@+id/checkBox4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/h_gardening" />
        </LinearLayout>
    
        <CheckBox
            android:id="@+id/checkBox5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/h_football" />
    
        <Button
            android:id="@+id/next1"
            android:layout_width="93dp"
            android:layout_height="wrap_content"
            android:text="@string/b1_text" />
    </LinearLayout>
    </ScrollView>
    
    </FrameLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-04
      • 1970-01-01
      • 1970-01-01
      • 2014-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多