2017-04-05 92 views
-2

我想對圓形圖像進行大型測試。就像這樣:圓形圖像文本

enter image description here

+1

你嘗試過什麼到目前爲止? –

+0

你只需要在手機上顯示文字,還是應該保存的圖像? –

+0

你只需要一個帶圓形繪製的TextView作爲其背景。 –

回答

1

你可以做到這一點有兩種方式,

,如果你實際使用的圖形圖像,使用相對佈局,並把圖像視圖和TextView中作爲它的一個孩子。並確保你保持centerInParent參數的文本。

如果你不需要圖形資源,你可以創建一個自定義drawable,並將其設置爲你的textview的背景。

自定義繪製可以是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <corners android:radius="28dp" /> 
    <solid android:color="@color/THEME_GREEN_DARK" /> 
</shape> 

,然後你可以將其添加爲背景,以你的TextView。此外,根據您需要的圓圈大小更改您的半徑!

0

有這麼多庫做

內容添加到的build.gradle

repositories{ 
    maven { 
     url 'http://dl.bintray.com/amulyakhare/maven' 
    } 
} 

dependencies { 
    compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' 
} 

<ImageView android:layout_width="60dp" 
      android:layout_height="60dp" 
      android:id="@+id/image_view"/> 

注:指定的ImageView和繪製意志寬/高自動縮放以適應尺寸。

TextDrawable drawable = TextDrawable.builder() 
       .buildRect("FB", Color.RED); 

ImageView image = (ImageView) findViewById(R.id.image_view); 
image.setImageDrawable(drawable); 
4

試試這個:
在繪製文件夾中創建一個XML文件:

circular_bg.xml 

    <?xml version="1.0" encoding="utf-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval"> 
    <solid android:color="#B72854" /> 
    <padding 
     android:bottom="5dp" 
     android:left="5dp" 
     android:right="5dp" 
     android:top="5dp" /> 
    <size 
     android:width="15dp" 
     android:height="15dp" /> 
    </shape> 

然後在你的文本視圖背景中加入這一行:

  <TextView 
     android:id="@+id/textview" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:text="FB" 
     android:textColor="#fff" 
     android:textSize="20sp" 
     android:background="@drawable/circular_bg" 
     android:gravity="center_vertical|center_horizontal" 
     /> 

它會幫助你。 :)

2

最好的方法來使用按鈕和設置背景可繪製的外觀。

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="oval"> 

<solid android:color="@android:color/holo_red_dark" /> 

</shape> 

設置此可繪製按鈕背景並設置文本。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="center" 
android:orientation="vertical"> 

<Button 
    android:id="@+id/button" 
    android:layout_width="200dp" 
    android:layout_height="200dp" 
    android:background="@drawable/button_background" 
    android:text="FB" 
    android:textColor="@android:color/white" 
    android:textSize="35sp" /> 

</LinearLayout> 
0

希望這會有所幫助。由於

circular_drawable.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 

<solid 
android:color="#ff1e8f" /> 

<size 
android:width="120dp" 
android:height="120dp" /> 

<corners 
android:bottomLeftRadius="65dp" 
android:bottomRightRadius="65dp" 
android:topLeftRadius="65dp" 
android:topRightRadius="65dp" /> 

</shape> 

layout.xml

<TextView 
android:layout_width="120dp" 
android:layout_height="120dp" 
android:background="@drawable/circular_drawable" 
android:gravity="center" 
android:textColor="#FFFFFF" 
android:text="FB" 
android:textSize="26sp" 
android:layout_centerInParent="true"/>