-2
A
답변
1
두 가지 방법으로 그것을 할 수 있습니다,
당신이 실제로 그래픽 이미지를 사용하는 경우는, 상대 레이아웃을 사용하고의 자식으로 이미지 뷰와 텍스트 뷰를 배치합니다. centerInParent
매개 변수를 사용하여 텍스트 뷰를 유지하십시오.
그래픽 애셋이 필요하지 않은 경우 사용자 정의 드로어 블을 만들고 텍스트 뷰의 배경으로 설정할 수 있습니다.
사용자 정의 그릴 수는 다음과 같이 할 수있다 :
<?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>
을 그리고 당신은 당신의 텍스트 뷰에 배경으로 추가 할 수 있습니다. 또한 필요한 원의 크기에 따라 반지름을 변경하십시오!
0
는
이
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"/>
참고 build.gradle이를 추가 할 수있는 많은 libs가 있습니다 다음 이미지 뷰와 당김 의지에 대한 너비/높이를 지정합니다 크기에 맞게 자동 크기 조절.
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
가장 좋은 방법은 Button 및 배경 drawable 모양을 사용하는 것입니다.
<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"/>
당신은 지금까지 시도 무엇? –
휴대 전화에 텍스트를 표시하거나 이미지를 저장해야합니까? –
둥근 모양의 배경을 가진 TextView 만 필요합니다. –