最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android之TextView自適應(yīng)大小

 更新時(shí)間:2017年03月03日 10:05:10   作者:聽(tīng)著music睡  
對(duì)于設(shè)置TextView的字體默認(rèn)大小對(duì)于UI界面的好看程度是很重要的,小屏幕設(shè)置的文字過(guò)大或者大屏幕設(shè)置的文字過(guò)小都造成UI的不美觀?,F(xiàn)在就讓我們學(xué)習(xí)自適應(yīng)大小的TextView控件。下面跟著小編一起來(lái)看下吧

對(duì)于設(shè)置TextView的字體默認(rèn)大小對(duì)于UI界面的好看程度是很重要的,小屏幕設(shè)置的文字過(guò)大或者大屏幕設(shè)置的文字過(guò)小都造成UI的不美觀

現(xiàn)在就讓我們學(xué)習(xí)自適應(yīng)大小的TextView控件,即當(dāng)文字長(zhǎng)度變化時(shí),文字的大小會(huì)相應(yīng)的變化,保證顯示在一行當(dāng)中

實(shí)現(xiàn)依靠于第三方類(lèi)庫(kù)

第三方類(lèi)來(lái)源:

https://github.com/grantland/android-autofittextview

和正常的使用TextView一樣,只需要將要自適應(yīng)的TextView標(biāo)簽設(shè)置為<me.grantland.widget.AutofitTextView/>

注意:一定要設(shè)置為單行,否定無(wú)法顯示效果

android:singleLine="true"

<me.grantland.widget.AutofitTextView
   android:id="@+id/output_autofit"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:text="@string/example"
   android:textSize="50sp"
   android:gravity="center"
   android:singleLine="true"
   autofit:minTextSize="8sp"
   />

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"   xmlns:autofit="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="match_parent">
 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  >
  <EditText
   android:id="@+id/input"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:singleLine="true"
   android:hint="@string/input_hint"
   android:text="@string/example"/>
  <TextView
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:text="@string/label_normal"
   />
  <TextView
   android:id="@+id/output"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:text="@string/example"
   android:textSize="50sp"
   android:gravity="center"
   />
  <TextView
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:text="@string/label_autofit"
   />
  <me.grantland.widget.AutofitTextView
   android:id="@+id/output_autofit"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:text="@string/example"
   android:textSize="50sp"
   android:gravity="center"
   android:singleLine="true"
   autofit:minTextSize="8sp"
   />
 </LinearLayout>
</ScrollView>

activity_main.xml

string.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <string name="app_name">Texttest</string>
 <string name="action_settings">Settings</string>
 <string name="hello_world">Hello world!</string>
 <string name="input_hint">text</string>
 <string name="label_normal">Normal:</string>
 <string name="label_autofit">Autofit:</string>
 <string name="example">This is an example</string>
</resources>

activity

package com.example.texttest;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
 private TextView mOutput;
 private TextView mAutofitOutput;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  mOutput = (TextView)findViewById(R.id.output);
  mAutofitOutput = (TextView)findViewById(R.id.output_autofit);
  ((EditText)findViewById(R.id.input)).addTextChangedListener(new TextWatcher() {
   @Override
   public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
    // do nothing
   }
   @Override
   public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
    mOutput.setText(charSequence);
    mAutofitOutput.setText(charSequence);
   }
   @Override
   public void afterTextChanged(Editable editable) {
    // do nothing
   }
  });
 }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.main, menu);
  return true;
 }
}

MainActivity.java

效果:

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

  • Android通過(guò)Service實(shí)現(xiàn)簡(jiǎn)單的音樂(lè)播放

    Android通過(guò)Service實(shí)現(xiàn)簡(jiǎn)單的音樂(lè)播放

    這篇文章主要介紹了Android通過(guò)Service實(shí)現(xiàn)簡(jiǎn)單的音樂(lè)播放,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • Android調(diào)用第三方QQ登錄代碼分享

    Android調(diào)用第三方QQ登錄代碼分享

    現(xiàn)在的項(xiàng)目開(kāi)發(fā),調(diào)用第三方登錄,幾乎是必須的,這篇文章主要介紹了Android調(diào)用第三方QQ登錄代碼分享
    2016-05-05
  • 詳解Android 裸眼3D效果View控件

    詳解Android 裸眼3D效果View控件

    主要的設(shè)計(jì)核心是依賴(lài)于傳感器對(duì)手機(jī)晃動(dòng)的監(jiān)聽(tīng)(重力感應(yīng)監(jiān)聽(tīng)器),對(duì)每層圖片進(jìn)行不同的移動(dòng),實(shí)現(xiàn)仿3D效果。本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2021-08-08
  • Android如何自定義視圖屬性

    Android如何自定義視圖屬性

    這篇文章主要為大家介紹了Android如何自定義視圖屬性,三個(gè)步驟自定義視圖屬性,感興趣的小伙伴們可以參考一下
    2016-08-08
  • android開(kāi)發(fā)教程之實(shí)現(xiàn)toast工具類(lèi)

    android開(kāi)發(fā)教程之實(shí)現(xiàn)toast工具類(lèi)

    這篇文章主要介紹了android開(kāi)發(fā)中需要的toast工具類(lèi),需要的朋友可以參考下
    2014-05-05
  • Android Git submodule詳解用法示例

    Android Git submodule詳解用法示例

    項(xiàng)目中經(jīng)常會(huì)使用到第三方的 git 庫(kù), 將三方庫(kù)整合到項(xiàng)目中最簡(jiǎn)單的辦法就是復(fù)制粘貼, 但是如果這個(gè)庫(kù)升級(jí)了一個(gè)很酷炫的功能, 你要怎么整合進(jìn)來(lái)呢?(其實(shí)就是 git 版的包管理器)這就是本次要介紹的 git-submodule 操作, 直接把第三方的版本庫(kù)合并到自己的庫(kù)中
    2021-11-11
  • Android 通過(guò)cmake的方式接入opencv的方法步驟

    Android 通過(guò)cmake的方式接入opencv的方法步驟

    這篇文章主要介紹了Android 通過(guò)cmake的方式接入opencv的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • android 監(jiān)聽(tīng)SD卡文件變化的實(shí)現(xiàn)代碼

    android 監(jiān)聽(tīng)SD卡文件變化的實(shí)現(xiàn)代碼

    這篇文章主要介紹了android 監(jiān)聽(tīng)SD卡文件變化的實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2017-11-11
  • Android Compose自定義TextField實(shí)現(xiàn)自定義的輸入框

    Android Compose自定義TextField實(shí)現(xiàn)自定義的輸入框

    眾所周知Compose中默認(rèn)的TextField和OutlineTextField樣式并不能滿(mǎn)足所有的使用場(chǎng)景,所以自定義TextField就成了必備技能。本文將自定義TextField實(shí)現(xiàn)自定義的輸入框,感興趣的可以了解一下
    2022-03-03
  • Android編程實(shí)現(xiàn)獲取多媒體庫(kù)視頻、音頻、圖片的方法

    Android編程實(shí)現(xiàn)獲取多媒體庫(kù)視頻、音頻、圖片的方法

    這篇文章主要介紹了Android編程實(shí)現(xiàn)獲取多媒體庫(kù)視頻、音頻、圖片的方法,涉及Android針對(duì)多媒體視頻、音頻及相關(guān)專(zhuān)輯圖片、縮略圖等獲取操作實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2018-01-01

最新評(píng)論

五河县| 阿拉尔市| 会东县| 青川县| 响水县| 延长县| 呈贡县| 宁蒗| 田阳县| 贡觉县| 泗阳县| 五华县| 咸宁市| 青龙| 芮城县| 泽州县| 吉木萨尔县| 黔西县| 略阳县| 周口市| 北宁市| 玉树县| 敦化市| 德兴市| 桐城市| 台东市| 龙陵县| 江油市| 中牟县| 东明县| 称多县| 蚌埠市| 沙田区| 乐清市| 阿合奇县| 西贡区| 东海县| 高淳县| 台南市| 铁力市| 博兴县|