국경 주변에 테스트비에프 그릴 수 있습니까?
드로어 블 모양을 설정할 수 있습니다 (사각형) 를 배경으로 보기입니다.
<TextView android:text="Some text" android:background="@drawable/back"/>
및 사각형에는 드로어 블 박.1믈 (res / 드로어 블 넣을 폴더):
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@android:color/white" />
<stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>
'대한' @android:color/transparent 단색 배경 가지고 투명해집니다 사용할 수 있습니다. 국경 의 텍스트를 분리하십시오 여백을 사용할 수도 있습니다. 자세한 내용은: http://developer.android.com/guide/topics/resources/drawable-resource.html
Let me 요약하십시오 몇 개의 다른 (비사양 프로그램) 방법.
다음 XML 파일로 저장할 수 있는 드로어 블 폴더 (예를 들어, my_border.xml):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- View background color -->
<solid
android:color="@color/background_color" >
</solid>
<!-- View border color and width -->
<stroke
android:width="1dp"
android:color="@color/border_color" >
</stroke>
<!-- The radius makes the corners rounded -->
<corners
android:radius="2dp" >
</corners>
</shape>
방금 설정한 후 이를 배경으로 렌더링합니다 데이터베이스에구성원을 테스트비에프:
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/my_border" />
더 많은 도움말:
9 패치합니다 는 신축성 있는 배경 이미지입니다. 테두리가 있는 경우 그 이미지를 만들기 테스트비에프 제공하세요 것이라고 말했습니다. All you need to do it in your 테스트비에프 배경에 이미지와 설정한 후 할 수 있다.
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/my_ninepatch_image" />
다음은 보일 수 있는 링크를 만드는 방법을 9 패치합니다 이미지:
서로 위에 두 개의 사각형이 레이어에는 스택할 list 를 사용할 수 있습니다. 두 번째 사각형에는 조금 먼저 만들어 보다 작은 사각형 테두리 효과를 할 수 있습니다. 첫 번째 (아래쪽) 는, 두 번째 사각형에는 배경색입니다 사각형에는 테두리 색상이 있다.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Lower rectangle (border color) -->
<item>
<shape android:shape="rectangle">
<solid android:color="@color/border_color" />
</shape>
</item>
<!-- Upper rectangle (background color) -->
<item android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="@color/background_color" />
</shape>
</item>
</layer-list>
안드로이드 설정 ',' 위 (때문에 소형), 2dp" 오프셋합니다 상단형: = " 의해 2dp. 따라서 첫 번째 (아래쪽) 로, 사각형 테두리 확증하노라 투시되지 효과를 얻을 수 있습니다. 이 같은 방법을 적용할 수 있는 '형태' 드로어 블 테스트비에프 배경 위에 완료되었다.
그 밖에 대한 링크 레이어 목록:
단 한 번의 국경 9 패치합니다 이미지를 만들 수 있습니다. 위에서 설명한 아무도요 설명하였노라 동일합니까.
그러나 이 같은 전략은 국경 사이에 2 개의 보기 또는 제프 레이터 작동하잖아 잘 추가해야 할 경우 단일 테스트비에프.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- This adds a border between the TextViews -->
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@android:color/black" />
<TextView
android:id="@+id/textview2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
그 밖에 링크:
[1]: http://developer.android.com/guide/topics/resources/drawable-resource.html # 모양
간단한 방법은 추가 단축시킵니다 보기입니다 테스트비에프. 예 바닥 테두리 라인:
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:text="@string/title"
android:id="@+id/title_label"
android:gravity="center_vertical"/>
<View
android:layout_width="fill_parent"
android:layout_height="0.2dp"
android:id="@+id/separator"
android:visibility="visible"
android:background="@android:color/darker_gray"/>
</LinearLayout>
다른 방향선이 대한 경계를 위치를 조정하십시오 seperator 보기입니다.
나는 이 문제를 해결할 연장하여 테스트비에프 및 드로잉 테두리가 합니다. 난 심지어 추가되든지 경우 선택할 수 있도록 테두리는 점선 또는 태세에 돌입했다.
public class BorderedTextView extends TextView {
private Paint paint = new Paint();
public static final int BORDER_TOP = 0x00000001;
public static final int BORDER_RIGHT = 0x00000002;
public static final int BORDER_BOTTOM = 0x00000004;
public static final int BORDER_LEFT = 0x00000008;
private Border[] borders;
public BorderedTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public BorderedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public BorderedTextView(Context context) {
super(context);
init();
}
private void init(){
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.BLACK);
paint.setStrokeWidth(4);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(borders == null) return;
for(Border border : borders){
paint.setColor(border.getColor());
paint.setStrokeWidth(border.getWidth());
if(border.getStyle() == BORDER_TOP){
canvas.drawLine(0, 0, getWidth(), 0, paint);
} else
if(border.getStyle() == BORDER_RIGHT){
canvas.drawLine(getWidth(), 0, getWidth(), getHeight(), paint);
} else
if(border.getStyle() == BORDER_BOTTOM){
canvas.drawLine(0, getHeight(), getWidth(), getHeight(), paint);
} else
if(border.getStyle() == BORDER_LEFT){
canvas.drawLine(0, 0, 0, getHeight(), paint);
}
}
}
public Border[] getBorders() {
return borders;
}
public void setBorders(Border[] borders) {
this.borders = borders;
}
}
및 국경 클래스:
public class Border {
private int orientation;
private int width;
private int color = Color.BLACK;
private int style;
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getColor() {
return color;
}
public void setColor(int color) {
this.color = color;
}
public int getStyle() {
return style;
}
public void setStyle(int style) {
this.style = style;
}
public int getOrientation() {
return orientation;
}
public void setOrientation(int orientation) {
this.orientation = orientation;
}
public Border(int Style) {
this.style = Style;
}
}
따라서 누군가가 바랍니다:)
그냥 보면 비슷한 답 - it& # 39 의 할 수 있는 수행됨 선과 정보정의다음 재지정입니다:
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
Paint strokePaint = new Paint();
strokePaint.setARGB(255, 0, 0, 0);
strokePaint.setTextAlign(Paint.Align.CENTER);
strokePaint.setTextSize(16);
strokePaint.setTypeface(Typeface.DEFAULT_BOLD);
strokePaint.setStyle(Paint.Style.STROKE);
strokePaint.setStrokeWidth(2);
Paint textPaint = new Paint();
textPaint.setARGB(255, 255, 255, 255);
textPaint.setTextAlign(Paint.Align.CENTER);
textPaint.setTextSize(16);
textPaint.setTypeface(Typeface.DEFAULT_BOLD);
canvas.drawText("Some Text", 100, 100, strokePaint);
canvas.drawText("Some Text", 100, 100, textPaint);
super.draw(canvas, mapView, shadow);
}
두 가지 방법을 통해 국경 설정할 수 있습니다. 두 번째는 드로어 블 한 프로그램 () 이다.
<shape>
<solid android:color="@color/txt_white"/>
<stroke android:width="1dip" android:color="@color/border_gray"/>
<corners android:bottomLeftRadius="10dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="10dp"
android:topRightRadius="0dp"/>
<padding android:bottom="0dip"
android:left="0dip"
android:right="0dip"
android:top="0dip"/>
</shape>
프로그램
public static GradientDrawable backgroundWithoutBorder(int color) {
GradientDrawable gdDefault = new GradientDrawable();
gdDefault.setColor(color);
gdDefault.setCornerRadii(new float[] { radius, radius, 0, 0, 0, 0,
radius, radius });
return gdDefault;
}
아래 링크를 확인할 수 있도록 둥근 http://androidcookbook.com/Recipe.seam = 2318 레시페이드?
이 프로젝트는 비트맵입니다 드로어 블 폴더에서는 go-dell res, 안드로이드, PNG (또는 JPG 파일) 에 국한되지 않습니다 하지만 XML 파일에 정의된 모양을 가질 수도 있습니다.
이 프로젝트의 재사용됩니다 날까로움 스왑할 수 있습니다. 경계선을 레이아웃용 넣을 수 있는 모양 사용할 수 있습니다. 이 예제에서와 사각형 국경 커브된 코너입니다. 새로운 파일 호출됨 커스트롬보르데리스마르 만들어집니다 드로어 블 폴더 (의 Eclipse 파일을 사용하여 메뉴 및 일부 새로운 어졌다면 파일, 폴더 선택된 파일 이름을 입력 후 함께 드로어 블 스크립트종료).
Xml 정의중 국경 모양에만 입력되었는지:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp"/>
<padding android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp"/>
<solid android:color="#CCCCCC"/>
</shape>
속성 '안드로이드' 로 설정되었습니다 사각형에는: 모양 (shape 파일도 지원부에서는 oval, 선, ring). 때문에 이 속성이 사각형에는 기본값입니다 될 경우 왼쪽 아웃해야 사각형에는 정의되는. 안드로이드 모양에 대한 자세한 내용은 http://developer.android.com/guide/topics/resources/drawable-resource.html # 모양에만 지켜보리니 붽뎄 emc. 모양 절실해졌습니다.
이 코너는 라운드될 요소점 코너를 사각형에는 설정합니다. 이는 서로 다른 반지름입니다 모퉁이점을 설정할 수 있습니다 (자세한 내용은 안드로이드 참조).
뷰의 내용을 이동할 수 있는 패딩 속성을 사용하는 것을 막기 위해 이 내용을 중첩되도록 모양에만 적용됩니다. 정의하였다.
여기 이 테두리 색상이 밝은 회색 (카치치 십육진법 RGB 값을) 로 설정되어 있습니다.
하지만 여기서 사용하지 않는 그래디언트 날까로움 지원하고 있다. 안드로이드 리소스에는 http://schmidt. devlib. 다시 확인할 수 있는 그래디언트 정의됩니다. 모양은 '안드로이드' 를 사용하여, 배경 = " @drawable/customborder" 레이푸트 적용됩니다.
레이아웃 내의 다른 뷰를 정상적으로 추가할 수 있습니다. 이 예제에서는 하나의 테스트비에프 추가되었음, 그리고 텍스트는 화이트 (FFFFFF 십육진법 RGB). 블루, 그리고 배경 설정되었습니다 줄이기 위해 일부 투명도로 단추밝기 (알파 A00000FF 십육진법 RGB 값을). 마지막으로 레이아웃뿐만 오프셋됩니다 면쪽 배치하여 화면을 통해 다른 영역으로 레이아웃뿐만 아주 적은 양의 패딩. 전체 레이아웃뿐만 파일 되고 있다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/customborder">
<TextView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Text View"
android:textSize="20dp"
android:textColor="#FFFFFF"
android:gravity="center_horizontal"
android:background="#A00000FF" />
</LinearLayout>
</LinearLayout>
나는 그렇게 할 수 있는 방법을 간단히 말해, d # 39 와 같은 I& 공유할 수 있습니다.
내가 원할 때, 난 그냥 둘 수 있는 제곱마일 테스트비우스 린얼리우스. 난 내 린얼리우스, 난 내 테스트비에프 추가하기에서는 마진이 배경색입니다 설정합니다. 그 결과, 이 때 광장 당근이지를 테스트비에프.
ImageView selectionBorder = BorderDrawer.generateBorderImageView(context, borderWidth, borderHeight, thickness, Color.Blue);
다음은 코드.
/**
* Because creating a border is Rocket Science in Android.
*/
public class BorderDrawer
{
public static ImageView generateBorderImageView(Context context, int borderWidth, int borderHeight, int borderThickness, int color)
{
ImageView mask = new ImageView(context);
// Create the square to serve as the mask
Bitmap squareMask = Bitmap.createBitmap(borderWidth - (borderThickness*2), borderHeight - (borderThickness*2), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(squareMask);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(color);
canvas.drawRect(0.0f, 0.0f, (float)borderWidth, (float)borderHeight, paint);
// Create the darkness bitmap
Bitmap solidColor = Bitmap.createBitmap(borderWidth, borderHeight, Bitmap.Config.ARGB_8888);
canvas = new Canvas(solidColor);
paint.setStyle(Paint.Style.FILL);
paint.setColor(color);
canvas.drawRect(0.0f, 0.0f, borderWidth, borderHeight, paint);
// Create the masked version of the darknessView
Bitmap borderBitmap = Bitmap.createBitmap(borderWidth, borderHeight, Bitmap.Config.ARGB_8888);
canvas = new Canvas(borderBitmap);
Paint clearPaint = new Paint();
clearPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
canvas.drawBitmap(solidColor, 0, 0, null);
canvas.drawBitmap(squareMask, borderThickness, borderThickness, clearPaint);
clearPaint.setXfermode(null);
ImageView borderView = new ImageView(context);
borderView.setImageBitmap(borderBitmap);
return borderView;
}
}
콘스탄틴 부로프 변경됩니까 오토메이티드 작업하십시오 않았기 때문에 내 사례:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
<stroke android:width="2dip" android:color="#4fa5d5"/>
<corners android:radius="7dp"/>
</shape>
</item>
</selector>
comp일스트크버시온 26 (안드로이드 8.0), 민스데크버시온 21 (안드로이드 5.0) 타르제스데크버시온 26,
gradle:4.1
이 도움이 될 수 있습니다.
<RelativeLayout
android:id="@+id/textbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@android:color/darker_gray" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="3dp"
android:background="@android:color/white"
android:gravity="center"
android:text="@string/app_name"
android:textSize="20dp" />
</RelativeLayout
사용자 정의 배경 텍스트의 경치말이야 만들 수 있습니다. 단계를
<, 모양, http://schemas.android.com/apk/res/android", >, 안드로이드 = " xmlns 를: width = " <, 선, 1dp", 안드로이드. color = ", @color/colorBlack", 안드로이드. />. <, 패딩, 왼쪽 = " 1dp", 안드로이드. 안드로이드: 상단형 = " 1dp"; 오른쪽 = ", 1dp", 안드로이드. 아래 = ", 1dp", 안드로이드. />. 코너를 <, 안드로이드, 6dp" " 반지름입니다 =. />. , # ffffffff" color = " < 솔리드로 안드로이드. />. < /shape>;
안드로이드: 배경 = " @drawable/your_fileName";
테두리가 맞추기바인딩 테스트비에프 추가하는 방안도 아주 많습니다. 가장 간단한 하나는 정보기술 (it) 을 설정하고, 배경 = " 안드로이드 사용자 정의 드로어 블 만들어 ',' 단축시킵니다 @drawable/textview_bg" 테스트비에프.:
이 textview_bg.xml 드로어 블 따라 갈 수 있으며 이 같은 일이. '또는' 있을 수 있습니다 '솔리드로 그래디언트' 배경 (또는 아무것도아니야 필요 없는 경우), '코너' 와 '선' 을 추가 모퉁이점을 반지름입니다 추가 정의하였다.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="@dimen/dp_10"/>
<gradient
android:angle="225"
android:endColor="#FFFFFF"
android:startColor="#E0E0E0" />
<stroke
android:width="2dp"
android:color="#000000"/>
</shape>
사실 매우 간단합니다. 간단한 스케쳐내 검은 배경 = ", 안드로이드, 뒤에 사각형에는 테스트비에프 추가하기만 ',' @android:color/black" 테스트비에프 내의 주기표시.: 다음과 같습니다.
<TextView
android:textSize="15pt" android:textColor="#ffa7ff04"
android:layout_alignBottom="@+id/webView1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="@android:color/black"/>