ScrollView не работает с фиксированным нижним колонтитулом - PullRequest
0 голосов
/ 28 мая 2018

Я работаю на экране для отображения фиксированного нижнего колонтитула и другого контента с scrollview.Но содержимое не прокручивалось.

ниже - мой код

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relateId"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_alignParentTop="true"
        android:layout_gravity="center"
        android:background="#689F38"
        android:gravity="center">

        <TextView
            android:id="@+id/header_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="header_msg"
            android:textColor="#FFFFFF"
            android:textSize="25sp" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_alignParentBottom="true"
        android:layout_gravity="center"
        android:background="#689F38"
        android:gravity="center">

        <TextView
            android:id="@+id/footer_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="footer"
            android:textColor="#FFFFFF"
            android:textSize="25sp" />
    </RelativeLayout>

    <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/footer"
        android:layout_below="@+id/header"
        android:fillViewport="true">

        <LinearLayout
            android:id="@+id/myLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FFFFFF"
            android:fillViewport="true"
            android:orientation="vertical">

            <TextView
                android:id="@+id/bodytext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@string/large_text"
                android:textColor="#F44336"
                android:textSize="25sp" />
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

ниже - скриншоты.То, что я получаю enter image description here

ниже - изображение, которое я получаю после прокрутки

enter image description here

Как показано на картинках выше, Foorter не прилипает к экрану.Когда я использую приведенный выше код, содержимое отображалось до размера экрана.после я не могу прокрутить, чтобы просмотреть оставшийся контент.Не знаю точную проблему.Пожалуйста, кто-нибудь, помогите мне.

1 Ответ

0 голосов
/ 28 мая 2018

sample.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/res-auto"
              xmlns:tools="http://schemas.android.com/tools"
              android:id="@+id/relateId"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_gravity="center"
        android:background="#689F38"
        android:gravity="center">

        <TextView
            android:id="@+id/header_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="header_msg"
            android:textColor="#FFFFFF"
            android:textSize="25sp"/>
    </RelativeLayout>

    <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        >

        <LinearLayout
            android:id="@+id/myLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:fillViewport="true"
            android:orientation="vertical">

            <TextView
                android:id="@+id/bodytext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@string/large_text"
                android:textColor="#F44336"
                android:textSize="25sp"/>
        </LinearLayout>
    </ScrollView>

    <RelativeLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_gravity="center"
        android:background="#689F38"
        android:gravity="center">

        <TextView
            android:id="@+id/footer_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="footer"
            android:textColor="#FFFFFF"
            android:textSize="25sp"/>
    </RelativeLayout>

</LinearLayout>

Изменить для вашего требования

Ниже приведен полный код, который я протестировал с приведенным выше макетом XML.

public class ActivitySample extends BaseProject {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sample);
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="in.kpis.structure">

    <application
        android:name="in.kpis.structure.appClasses.ApplicationContext"
        android:icon="@mipmap/ic_launcher"
        android:theme="@style/AppTheme"
        >
        <activity android:name=".appClasses.activities.ActivitySample">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

    </application>
</manifest>

в res>values>styles.xml

<resources xmlns:tools="http://schemas.android.com/tools">

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
 //....other styles
</resources>
...