简体   繁体   English

如何使 PreferenceScreen 的标题可调整大小?

[英]How to make title of PreferenceScreen resizable?

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                  android:title="@string/game_title">

I've a preference screen for my app for which I've added the title.我为我的应用添加了标题的首选项屏幕。 When the app gets opened in split screen and resized to different size in window, the title is disappearing when the width present is smaller.当应用程序在分屏中打开并在 window 中调整为不同大小时,当存在的宽度较小时,标题会消失。

Tried adding,尝试添加,

android:layout_height="wrap_content"
android:layout_width="wrap_content"

property to the PreferenceScreen but it didn't help. PreferenceScreen的属性,但它没有帮助。 Some help would be appreciated.一些帮助将不胜感激。

Like in this answer , you can create a custom layout for the PreferenceScreen and apply it with android:layout attribute就像在这个答案中一样,您可以为PreferenceScreen创建自定义布局并使用android:layout属性应用它

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout="@layout/preference_title"
                  android:title="@string/game_title">

preference_title.xml layout preference_title.xml 布局

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@android:id/title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="@dimen/preference_title"/>

And create different versions of res/values/dimen.xml file to have variable value of the title text size ( @dimen/preference_title ) that are proportional to possible screen widths.. typically you'll have different versions values directory, for instance for a screen width of w600dp, you'll have values-w600dp directory.并创建不同版本的res/values/dimen.xml文件以具有与可能的屏幕宽度成正比的标题文本大小 ( @dimen/preference_title ) 的可变值。通常您将拥有不同版本的values目录,例如屏幕宽度为 w600dp,您将拥有values-w600dp目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM