PreferenceFragment надувается на CardView

У меня возникли проблемы с правильной компоновкой layout_height, когда я накачиваю PreferenceFragment в CardView.

Все работает хорошо, включая NestedScrollView, чтобы свернуть мою панель инструментов, но по каким-то причинам мои настройки занимают только первую позицию в списке. Это прокручиваемый, но он должен заполнить всю карту.

Есть идеи о том, что здесь может происходить?

Редактировать: это определенно NestedScrollView вызывает проблему. Теперь, если только я могу найти обходной путь..

Я мог бы также не полностью понимать Карты, так как другие Макеты, я не могу заставить их полностью заполнить Вид, за исключением этого небольшого запаса.

Вот мой PreferenceFragment XML

<android.support.v7.widget.CardView

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/tools"

android:id="@+id/cardview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:elevation="100dp"
android:layout_gravity="center"
android:layout_margin="10dp"
card_view:cardBackgroundColor="@color/cardview_initial_background"
card_view:cardCornerRadius="10dp"

app:layout_behavior="@string/appbar_scrolling_view_behavior">

<android.support.v4.widget.NestedScrollView

    android:id="@+id/nestedScrollView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="@dimen/scrollview_padding_default" >

    <LinearLayout

        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:background="@android:color/transparent">

        <ListView

            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="0px"
            android:layout_weight="1"
            android:paddingTop="0dip"
            android:paddingBottom="@dimen/preference_fragment_padding_bottom"
            android:paddingLeft="@dimen/preference_fragment_padding_side"
            android:paddingRight="@dimen/preference_fragment_padding_side"
            android:scrollbarStyle="@integer/preference_fragment_scrollbarStyle"
            android:clipToPadding="false"
            android:drawSelectorOnTop="false"
            android:cacheColorHint="@android:color/transparent"
            android:scrollbarAlwaysDrawVerticalTrack="true" />

        <TextView

            android:id="@android:id/empty"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="@dimen/preference_fragment_padding_side"
            android:gravity="center"
            android:visibility="gone" />

        <RelativeLayout

            android:id="@+id/button_bar"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:layout_weight="0"
            android:visibility="gone">

            <Button

                android:id="@+id/back_button"
                android:layout_width="150dip"
                android:layout_height="wrap_content"
                android:layout_margin="5dip"
                android:layout_alignParentLeft="true"
                android:text="@string/back_button_label"/>

            <LinearLayout

                android:orientation="horizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true">

                <Button

                    android:id="@+id/skip_button"
                    android:layout_width="150dip"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dip"
                    android:text="@string/skip_button_label"
                    android:visibility="gone"/>

                <Button

                    android:id="@+id/next_button"
                    android:layout_width="150dip"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dip"
                    android:text="@string/next_button_label"/>

            </LinearLayout>

        </RelativeLayout>

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

</android.support.v7.widget.CardView>

И мой PreferenceFragment Java, где происходит инфляция:

package app.my.sample;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import app.my.sample.R;

public class SettingsPreferenceFragment extends PreferenceFragment {

public static final String ARG_PAGE = "ARG_PAGE";

private int mPage;

public static SettingsPreferenceFragment newInstance(int page) {

    Bundle args = new Bundle();
    args.putInt(ARG_PAGE, page);
    SettingsPreferenceFragment fragment = new SettingsPreferenceFragment();
    fragment.setArguments(args);

    return fragment;

}

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    mPage = getArguments().getInt(ARG_PAGE);
    addPreferencesFromResource(R.xml.preferences);

}

@Override
public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {

    return paramLayoutInflater.inflate(R.layout.fragment_preference_list, paramViewGroup , false);

    //return super.onCreateView(paramLayoutInflater, paramViewGroup, paramBundle);

}

}

1 ответ

Это старый вопрос, но, возможно, кто-то найдет этот ответ полезным. Попробуйте добавить атрибут android:fillViewport="true" в NestedScrollView,

Другие вопросы по тегам