【问题标题】:Android ScrollView does not show bottom content in FragmentAndroid ScrollView 在 Fragment 中不显示底部内容
【发布时间】:2017-02-22 05:38:03
【问题描述】:

我在 Android Studio 中启动了一个新的选项卡式活动项目。片段内容不显示最后一个控件“序列号”。在片段 xml 下方

<FrameLayout 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"
tools:context="com.example.ibrahimnehme.slidingtab.StockTakeFragment">

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="5dp">

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/part_number"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Part Number"
                android:inputType="text"
                android:maxLines="1"
                android:singleLine="true" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/part_description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Part Description"
                android:inputType="textMultiLine"
                android:maxLines="3"
                 />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/lotId"
            style="@style/InputLabel" />

            <Spinner
                android:id="@+id/LotId"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:prompt="@string/lotId"
                android:spinnerMode="dialog"
                android:padding="5dp"
                style="@style/Widget.AppCompat.Spinner.Underlined"
                android:layout_gravity="bottom"/>

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/Location"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Location"
                android:inputType="text"
                android:maxLines="1"
                />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/SubLocation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Sub Location"
                android:inputType="text"
                android:maxLines="1"
                />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/nsn"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="NSN"
                android:inputType="text"
                android:maxLines="1"
                />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/Unit_Of_Measurement"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Unit Of Measurement (UoM)"
                android:inputType="text"
                android:maxLines="1"
                />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/ControlId"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Control Id"
                android:inputType="text"
                android:maxLines="1"
                />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/Ext_Trace_Id"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Ext Trace Id"
                android:inputType="text"
                android:maxLines="1"
                />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/ExpiryDate"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Expiry Date"
                android:inputType="text"
                android:maxLines="1"
                />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/Status"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Status"
                android:inputType="text"
                android:maxLines="1"
                />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:paddingBottom="20dp"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/Serial_Number"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Serial Number"
                android:inputType="text"
                android:maxLines="1"
                />
        </android.support.design.widget.TextInputLayout>
    </LinearLayout>
</ScrollView>

最后一个可见控件是“状态”。我试图 PadBottom="20dp" 然后我用 RelativeLayout 包装 ScrollView 但仍然有同样的问题。

最低 SDK API 23 Android 6

非常感谢任何帮助。谢谢

【问题讨论】:

    标签: android fragment scrollview


    【解决方案1】:

    在不同的 xml 文件中定义片段的内容,然后将其包含在片段 xml 文件中,并改用 NestedScrollView

    <FrameLayout 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"
      tools:context="com.example.ibrahimnehme.slidingtab.StockTakeFragment">
    
      <android.support.v4.widget.NestedScrollView
          android:layout_width="match_parent"
          android:layout_height="match_parent">
    
       <include layout="@layout/yourOtherXMLFile"/>
    
      </android.support.v4.widget.NestedScrollView>
    </FrameLayout>
    

    【讨论】:

      【解决方案2】:

      您删除了 android.support.design.widget.TextInputLayout 中的填充

      <android.support.design.widget.TextInputLayout
                  android:layout_width="match_parent"
                  android:paddingBottom="20dp"
                  android:layout_height="wrap_content">
      
                  <AutoCompleteTextView
                      android:id="@+id/Serial_Number"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:hint="Serial Number"
                      android:inputType="text"
                      android:maxLines="1"
                      />

      删除 android:paddingBottom="20dp"

      【讨论】:

      • 添加 android:marginBottom="20dp" 对你有帮助
      【解决方案3】:

      添加android:fillViewPort="true" 所以

      变成了

      <FrameLayout 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"
      tools:context="com.example.ibrahimnehme.slidingtab.StockTakeFragment">
      
          <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="match_parent"
          android:fillViewPort="true">
      
              <LinearLayout
                  android:layout_width="fill_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical"
                  android:padding="5dp">
      
                  <android.support.design.widget.TextInputLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content">
      
                      <AutoCompleteTextView
                          android:id="@+id/part_number"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:hint="Part Number"
                          android:inputType="text"
                          android:maxLines="1"
                          android:singleLine="true" />
                  </android.support.design.widget.TextInputLayout>
      
                  <android.support.design.widget.TextInputLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content">
      
                      <AutoCompleteTextView
                          android:id="@+id/part_description"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:hint="Part Description"
                          android:inputType="textMultiLine"
                          android:maxLines="3"
                           />
                  </android.support.design.widget.TextInputLayout>
      
                  <android.support.design.widget.TextInputLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content">
      
                  <TextView
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:text="@string/lotId"
                      style="@style/InputLabel" />
      
                      <Spinner
                          android:id="@+id/LotId"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"
                          android:prompt="@string/lotId"
                          android:spinnerMode="dialog"
                          android:padding="5dp"
                          style="@style/Widget.AppCompat.Spinner.Underlined"
                          android:layout_gravity="bottom"/>
      
                  </android.support.design.widget.TextInputLayout>
      
                  <android.support.design.widget.TextInputLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content">
      
                      <AutoCompleteTextView
                          android:id="@+id/Location"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:hint="Location"
                          android:inputType="text"
                          android:maxLines="1"
                          />
                  </android.support.design.widget.TextInputLayout>
      
                  <android.support.design.widget.TextInputLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content">
      
                      <AutoCompleteTextView
                          android:id="@+id/SubLocation"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:hint="Sub Location"
                          android:inputType="text"
                          android:maxLines="1"
                          />
                  </android.support.design.widget.TextInputLayout>
      
                  <android.support.design.widget.TextInputLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content">
      
                      <AutoCompleteTextView
                          android:id="@+id/nsn"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:hint="NSN"
                          android:inputType="text"
                          android:maxLines="1"
                          />
                  </android.support.design.widget.TextInputLayout>
      
                  <android.support.design.widget.TextInputLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content">
      
                      <AutoCompleteTextView
                          android:id="@+id/Unit_Of_Measurement"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:hint="Unit Of Measurement (UoM)"
                          android:inputType="text"
                          android:maxLines="1"
                          />
                  </android.support.design.widget.TextInputLayout>
      
                  <android.support.design.widget.TextInputLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content">
      
                      <AutoCompleteTextView
                          android:id="@+id/ControlId"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:hint="Control Id"
                          android:inputType="text"
                          android:maxLines="1"
                          />
                  </android.support.design.widget.TextInputLayout>
      
                  <android.support.design.widget.TextInputLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content">
      
                      <AutoCompleteTextView
                          android:id="@+id/Ext_Trace_Id"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:hint="Ext Trace Id"
                          android:inputType="text"
                          android:maxLines="1"
                          />
                  </android.support.design.widget.TextInputLayout>
      
                  <android.support.design.widget.TextInputLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content">
      
                      <AutoCompleteTextView
                          android:id="@+id/ExpiryDate"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:hint="Expiry Date"
                          android:inputType="text"
                          android:maxLines="1"
                          />
                  </android.support.design.widget.TextInputLayout>
      
                  <android.support.design.widget.TextInputLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content">
      
                      <AutoCompleteTextView
                          android:id="@+id/Status"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:hint="Status"
                          android:inputType="text"
                          android:maxLines="1"
                          />
                  </android.support.design.widget.TextInputLayout>
      
                  <android.support.design.widget.TextInputLayout
                      android:layout_width="match_parent"
                      android:paddingBottom="20dp"
                      android:layout_height="wrap_content">
      
                      <AutoCompleteTextView
                          android:id="@+id/Serial_Number"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:hint="Serial Number"
                          android:inputType="text"
                          android:maxLines="1"
                          />
                  </android.support.design.widget.TextInputLayout>
              </LinearLayout>
          </ScrollView>
      

      我遇到了同样的问题。添加fillViewPort 使滚动视图填充其视图。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多