TextSwitcher的自动大小TextView

问题描述 投票:0回答:2

我看到Android在Oreo发布了textView的新属性:

android:autoSizeTextType

这会根据它显示的文本字符串调整textView的布局。

我怎么能用textSwitcher来使用它?

java android textview android-8.0-oreo
2个回答
-1
投票
 <?xml version="1.0" encoding="utf-8"?>
 <TextView
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/textView"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="@string/hello" />

 private ViewFactory viewFactory = new ViewFactory() {
    public View makeView()  {
        LayoutInflater inflater = LayoutInflater.from(TextSwitcherTest.this);
        TextView textView = (TextView) inflater.inflate(R.layout.textView, null);
        return textView;
    }
};

-1
投票
    altitudeSwitcher = (TextSwitcher) findViewById(R.id.altitude);
    altitudeSwitcher.setFactory(new ViewFactory() {

        @Override
        public View makeView() {


            TextView t = new TextView(getApplicationContext());
            t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
            t.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 50);

            return t;
        }
    });
© www.soinside.com 2019 - 2024. All rights reserved.