Tôi có một màn hình ưu tiên sử dụng một 'bố trí tùy chỉnh':Preference Screen Tuỳ chỉnh Layout chỉ làm việc với nhấp chuột thứ hai
android:layout="@layout/currencycodes"
Vấn đề này là nó không thể giúp hiển bố trí trên nỗ lực đầu tiên. Như bạn thấy từ gif động bên dưới, tôi phải rút lui và thử lại lần thứ hai để bố cục xuất hiện. Bây giờ tại sao vậy?
preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="application_preferences">
<PreferenceCategory>
<PreferenceScreen
android:key="url_settings"
android:title="@string/url_settings"
android:summary="@string/summary_url_settings">
</PreferenceScreen>
<PreferenceScreen
android:key="currency_codes"
android:title="@string/left_handed"
android:summary="@string/summary_left_handed">
<Preference
android:key="currency_exchanges"
android:layout="@layout/currencycodes"/>
</PreferenceScreen>
<EditTextPreference
android:key="url_exchange_rate"
android:title="@string/url_exchange_rate_settings"
android:summary="@string/summary_url_exchange_rate"
android:enabled = "false"/>
</PreferenceCategory>
</PreferenceScreen>
Sau đây là cách bố trí tùy chỉnh sử dụng. Nó chứa một GridView.
currencycodes.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context=".MainActivity">
<GridView
android:layout_width="328dp"
android:layout_height="479dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent" android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent" android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="16dp"
android:id="@+id/grdExchanges" android:scrollbars="horizontal|vertical"
android:smoothScrollbar="true" tools:textAlignment="center"
android:verticalScrollbarPosition="defaultPosition"/>
</android.support.constraint.ConstraintLayout>
xin vui lòng thêm java như cũng –