【问题标题】:Android ScrollView not working properly when use toolbar使用工具栏时,Android ScrollView 无法正常工作
【发布时间】:2015-10-06 12:19:10
【问题描述】:

我开发了一个 android 应用程序,其中滚动视图不滚动。我在这里发布代码请检查,如果发现任何错误请帮助。这里我使用 RelativeLayout 作为根,然后使用滚动视图和相对布局在滚动视图内和...在相对布局内编辑文本和微调器...但这不是向上滚动..

这是我的 XML :-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">

<LinearLayout
    android:id="@+id/ll1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <include
        android:id="@+id/tool_bar"
        layout="@layout/app_bar" />
</LinearLayout>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:scrollbars="none"
    android:layout_above="@+id/btnAccept"
    android:layout_below="@+id/ll1"
   >

    <RelativeLayout
        android:id="@+id/rel_input"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">

        <TextView
            android:id="@+id/txvPanmain"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:text="WANT TO GET IN TOUCH WITH US?"
            android:textColor="#131517"
            android:textSize="18sp"
            android:textStyle="bold" />

        <android.support.design.widget.TextInputLayout
            android:id="@+id/floatedtFullName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/txvPanmain"
            android:layout_marginTop="10dp">

            <EditText
                android:id="@+id/edtFullName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:focusable="true"
                android:hint="Full Name"
                android:inputType="textCapSentences"
                android:textColor="@android:color/black"
                android:textColorHint="#ff0000"
                android:textSize="18sp" />
        </android.support.design.widget.TextInputLayout>

        <Spinner
            android:id="@+id/spinCountry"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/floatedtFullName"
            android:layout_marginTop="15dp"
            android:entries="@array/country"
            android:prompt="@string/addressProof" />

        <View
            android:id="@+id/vspincountry"
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:layout_below="@+id/spinCountry"
            android:layout_marginTop="2dp"
            android:background="#000000" />

        <Spinner
            android:id="@+id/spinCity"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/vspincountry"
            android:layout_marginTop="15dp"
            android:entries="@array/country"
            android:prompt="@string/addressProof" />

        <View
            android:id="@+id/vspincity"
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:layout_below="@+id/spinCity"
            android:layout_marginTop="2dp"
            android:background="#000000" />


        <android.support.design.widget.TextInputLayout
            android:id="@+id/float_edit_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/vspincity"
            android:layout_marginTop="10dp">

            <EditText
                android:id="@+id/edtEmail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:focusable="true"
                android:hint="Email id"
                android:inputType="textEmailAddress"
                android:textColor="@android:color/black"
                android:textColorHint="#A4A4A4"
                android:textSize="18sp" />
        </android.support.design.widget.TextInputLayout>


        <android.support.design.widget.TextInputLayout
            android:id="@+id/float_edit_mobileno"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/float_edit_email"
            android:layout_marginTop="10dp">

            <EditText
                android:id="@+id/edtMobile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:focusable="true"
                android:hint="Mobile no."
                android:inputType="phone"
                android:maxLength="10"
                android:textColor="@android:color/black"
                android:textColorHint="#A4A4A4"
                android:textSize="18sp" />
        </android.support.design.widget.TextInputLayout>


        <Spinner
            android:id="@+id/spinFeedback"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/float_edit_mobileno"
            android:layout_marginTop="10dp"
            android:entries="@array/country"
            android:prompt="@string/addressProof" />

        <View
            android:id="@+id/vspinFeedback"
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:layout_below="@+id/spinFeedback"
            android:layout_marginTop="2dp"
            android:background="#000000" />


        <android.support.design.widget.TextInputLayout
            android:id="@+id/float_edit_comments"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/vspinFeedback"
            android:layout_marginTop="10dp">

            <EditText
                android:id="@+id/edtComments"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:focusable="true"
                android:inputType="text"
                android:hint="Comments"
                android:lines="3"
                android:maxLines="3"
                android:textColor="@android:color/black"
                android:textColorHint="#A4A4A4"
                android:textSize="18sp" />
        </android.support.design.widget.TextInputLayout>
    </RelativeLayout>
</ScrollView>



    <Button
        android:id="@+id/btnAccept"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/red"
        android:layout_alignParentBottom="true"
        android:padding="5dp"
        android:text="SUBMIT"
        android:textColor="@color/white_color"
        android:textSize="20sp"
        android:textStyle="normal" />


<ProgressBar
    android:id="@+id/progress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:visibility="gone" />
</RelativeLayout>

这是我的 app_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar        xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:paddingTop="@dimen/app_bar_top_padding"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar">

<TextView
    android:id="@+id/toolbar_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:textSize="22sp"
    android:textColor="@android:color/white"
    android:textStyle="bold"
    android:text="Toolbar Title" />
</android.support.v7.widget.Toolbar>

【问题讨论】:

  • 可以添加app_bar布局的代码吗?
  • 请添加app_bar布局代码
  • 检查 app_bar 布局
  • 我认为您需要在 ScrollView 和 RelativeLayout 之间添加 LinearLayout。并在 app_bar 布局中关闭 > 工具栏。
  • @Amardeepvijay 你的 xml 似乎对我有用,它可以正常滚动。 1)您错过了将 RelativeLayout 的结束标记放在 XML 布局中。 2)您可以为每个小部件提供更多的marginTop。因为您可能正在尝试不同尺寸的设备,因此可能无法滚动,请尝试使用一些小屏幕设备,例如 5" 设备...

标签: android android-layout scrollview android-xml android-scrollview


【解决方案1】:

您的 ScrollView 必须是定义的高度。尝试match_parent 而不是wrap_content。当 ScrollView 包装其内容时,您可能无法滚动到任何内容。

【讨论】:

  • App运行时你看到btnAccept和ProgressBar了吗?
猜你喜欢
  • 2013-11-24
  • 2016-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多