簡體   English   中英

在我的Android應用程序中,我想像下面的圖像一樣顯示textview嗎?

[英]In my android appciation i want to display textview like below image?

我想根據下面的圖像來顯示Textview,任何人都可以幫我。是否可以在Android中使用。

在此處輸入圖片說明

您可以使用transparent文本視圖:

<TextView 
...
android:background="@null"
...
/>

然后,如果您在布局中正確對齊它,則看起來像是您的圖像。

您必須更改文本的大小。可以使用SpannableStringBuilder進行更改。

SpannableStringBuilder spanTxt = new SpannableStringBuilder("Different");
spanTxt.append("text1");
//make the textsize 2 times.
spanTxt.setSpan(new RelativeSizeSpan(2f), spanTxt.length() - " text1".length(), spanTxt.length(), 0);

現在,將其設置為TextView的文本。

要獲取textView的邊框,您可以像這樣創建一個drawable並將其設置為TextView的背景

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <stroke
        android:width="1dp"
        android:color="@color/grey"/>
<!-- "#5D2E8C"  -->
    <solid android:color="#ffffff" />       <!-- background to the border -->
    <padding
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp" />
    <corners android:radius="0dp" />
</shape>

您可以通過在TextViews中使用以下屬性,使用RelativeLayout來完成此操作

 android:layout_marginLeft
 android:layout_marginRight
 android:layout_below
 android:layout_above
 android:layout_toLeftOf
 android:layout_toRightOf
  • 每個單詞使用不同的TextView(大,中,小文本視圖)

    即,通過在文本視圖中設置以下屬性

     android:textAppearance="?android:attr/textAppearanceLarge" android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceSmall" 
  • 將“邊界圖像”作為相對布局的背景

考慮將AbsoluteLayout或RelativeLayout用於動態內容。 另外,您可以通過Canvas類將文本繪制到位圖,然后簡單地繪制位圖。

Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_888);
Canvas c = new Canvas(bitmap);
c.drawText("Text", 0.0f, 0.0f, null); //Probably paint cannot be null

如果您的內容是靜態的,那么您可能應該只使用Perera的方法。

RelativeLayout-Android.com參考

AbsoluteLayout-Android.com參考

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM