buttonandroid圓角邊框-ag真人国际官网
❶ android button 怎麼消除邊框
使用資源文件shape定義背景(background)
下圖是安卓無憂中的例子,可以看裡面的源碼還有文檔,大部分形狀都可以定義,請看截圖:
在android程序開發中,我們經常會去用到shape這個東西去定義各種各樣的形狀,首先我們了解一下
shape下面有哪些標簽,都代表什麼意思:
1.1 solid:填充
android:color指定填充的顏色
1.2 gradient:漸變
android:startcolor和android:endcolor分別為起始和結束顏色,
android:angle是漸變角度,必須為45的整數倍。
另外漸變默認的模式為android:type="linear",即線性漸變,
可以指定漸變為徑向漸變,android:type="radial",徑向漸變需要指定半徑android:gradientradius="50"。
angle值對應的位置如圖:
1.3 stroke:描邊
android:width="2dp" 描邊的寬度,android:color 描邊的顏色。
我們還可以把描邊弄成虛線的形式,設置方式為:
android:dashwidth="5dp"
android:dashgap="3dp"
其中android:dashwidth表示'-'這樣一個橫線的寬度,android:dashgap表示之間隔開的距離
1.4 corners:圓角
android:radius為角的弧度,值越大角越圓。
我們還可以把四個角設定成不同的角度,
同時設置五個屬性,則radius屬性無效
android:radius="20dp" 設置四個角的半徑
android:topleftradius="20dp" 設置左上角的半徑
android:toprightradius="20dp" 設置右上角的半徑
android:bottomleftradius="20dp" 設置右下角的半徑
android:bottomrightradius="20dp" 設置左下角的半徑
padding:間隔
可以設置上下左右四個方向的間隔
ps:為了方便交流看一下我名字中文和除了中文以外的。
❷ 怎麼給android 設置邊框
總結一下android ui界面裡面如何設置邊框,以及如何把邊框設置成弧形的即圓角。
其實,android的ui里,界面一般都是比較簡單的,不會像web頁面那樣,數據量比較大,關於給android界面(表格)設置邊框,其思想很想我們用html設計表格然後給它設置邊框,如果你懂html的話。即通過給不同的控制項設置背景顏色來反襯出邊框線
以一個登錄界面為例,設置一個有邊框線的android 登錄界面:
註:本例要求的只是將該tablelayout中的行與行之間用邊框線隔開
此例中,採用tablelayout布局,非常簡單,裡面有3個tablerow,分別放置 用戶名、密碼、登錄按鈕,根據上面說的設置邊框線只需要設置控制項的背景顏色即可。這個例子中要求行與行之間有邊框線,那麼,就這么想,
tablelayout:是該界面的布局管理器(當然也是一個控制項),放在最外層,那麼這時你可以給它選一個背景顏色參考注釋 a)
tablerow:是表格中的一行,設置邊框線重點就在此,它是緊跟著tablelayout的,可以給tablerow(行)設置背景色,參考b)
tablelayout與tablerow關系:可以看成父與子的關系,那麼不管怎麼樣,tablelayout總是大於tablerow,那麼通過給二者設置不同的顏色,設置顏色的時候可以讓子組件(tablerow)周圍稍微留出一點邊界(就是它的背景色不會覆蓋完整個行,如何讓它顯示成這樣呢=====>android:layout_margin="0.5dip"[此屬性即是設置該組件周圍留出一點邊界])
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="
android:background="#ffcccccc" //a)給tablelayout設置背景色,改背景顏色將會是你要設置的邊框線的背景色
android:layout_margin="1dip"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99" //b)給tablerow設置背景色
android:layout_margin="0.5dip" //c)非常重要的一點
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="login name"
android:textstyle="bold"
android:layout_gravity="center_vertical" //如果想讓表格里的列與列(column之間)也有邊框線隔開,則同上面一樣也要設置android:background="#ffffcc99"與android:layout_margin="0.5dip"
>
android:layout_width="141px"
android:layout_height="wrap_content"
android:textsize="18sp"
android:background="#ffffffff"
android:textcolor="#ff000000"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99"
android:layout_margin="0.5dip"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="password"
android:textstyle="bold"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textsize="18sp"
android:background="#ffffffff"
android:textcolor="#ff000000"
>
❸ android中我shape里寫了邊框顏色、圓角,但調用過去沒實現。。。
你是說view占滿了整個屏幕嗎?這樣的話就只能在layout中寫一個布局文件,將view以一種組件的方式聲明到.xml文件中,然後你可以在它的上下中聲明其他的button或者textview或者imagebutton等。
❹ 安卓按鈕按下效果怎麼設置呢怎麼設置按鈕圓角和按下效果
可以通過shape設置圓角
android:color="#4285f4" >
通過selector設置點擊效果
button_bg.xml
在xml文件中設置button的background屬性。
android:background="@drawable/button_bg"
❺ android設置控制項樣式(邊框顏色,圓角)和圖片樣式(圓角)
本文鏈接:https://blog.csdn.net/weixin_37577039/article/details/79090433
```
android:toprightradius="5dp"
android:bottomrightradius="5dp"
android:bottomleftradius="5dp"/>
```
```
android:right="1dp"
android:left="1dp"
android:top="1dp"
android:bottom="1dp">
android:left="10dp"
android:right="10dp"
android:top="10dp" />
```
使用:
```android:background="@drawable/button_edge"```
```
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
android:radius="5dip" />
**設置文字padding**
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"
/>
```
```
android:toprightradius="10dp"
android:bottomrightradius="10dp"
android:bottomleftradius="10dp"/>
```
使用:
```
android:background="@drawable/image_circle"
```
```
glide.with(mainactivity.this).load(croppeduri)
.transform(new gliderectround(mainactivity.this,6)).into(headicon);
```
```
import android.content.context;
import android.content.res.resources;
import android.graphics.bitmap;
import android.graphics.bitmapshader;
import android.graphics.canvas;
import android.graphics.paint;
import android.graphics.rectf;
import android.util.log;
import com.bumptech.glide.load.engine.bitmap_recycle.bitmappool;
import com.bumptech.glide.load.resource.bitmap.bitmaptransformation;
/**
* created by sihao on 2018/3/3.
* glide 的 圓角 圖片 工具類
*/
public class gliderectround extends bitmaptransformation {
private static float radius = 0f;
// 構造方法1 無傳入圓角度數 設置默認值為5
public gliderectround(context context) {
this(context, 5);
}
// 構造方法2 傳入圓角度數
public gliderectround(context context, int dp) {
super(context);
// 設置圓角度數
radius = resources.getsystem().getdisplaymetrics().density * dp;
}
// 重寫該方法 返回修改後的bitmap
@override
protected bitmap transform(bitmappool pool, bitmap totransform, int outwidth, int outheight) {
return rectroundcrop(pool,totransform);
}
@override
public string getid() {
log.e("getid",getclass().getname() math.round(radius));
return getclass().getname() math.round(radius); // 四捨五入
}
private bitmap rectroundcrop(bitmappool pool, bitmap source){
if (source == null) return null;
bitmap result = pool.get(source.getwidth(), source.getheight(), bitmap.config.argb_8888); // argb_4444——代表4x4位argb點陣圖,argb_8888——代表4x8位argb點陣圖
if (result == null) {
result = bitmap.createbitmap(source.getwidth(), source.getheight(), bitmap.config.argb_8888);
}
canvas canvas = new canvas(result);
paint paint = new paint();
// setshader 對圖像進行渲染
// 子類之一 bitmapshader設置bitmap的變換 tilemode 有clamp (取bitmap邊緣的最後一個像素進行擴展),repeat(水平地重復整張bitmap)
//mirror(和repeat類似,但是每次重復的時候,將bitmap進行翻轉)
paint.setshader(new bitmapshader(source, bitmapshader.tilemode.clamp, bitmapshader.tilemode.clamp));
paint.setantialias(true); // 抗鋸齒
rectf rectf = new rectf(0f, 0f, source.getwidth(), source.getheight());
canvas.drawroundrect(rectf, radius, radius, paint);
return result;
}
}
```
圓角:
```
import android.content.context;
import android.graphics.bitmap;
import android.graphics.bitmapshader;
import android.graphics.canvas;
import android.graphics.paint;
import com.bumptech.glide.load.engine.bitmap_recycle.bitmappool;
import com.bumptech.glide.load.resource.bitmap.bitmaptransformation;
/**
* created by sihao on 2018/3/3.
* glide圓形圖片工具類
*/
public class glidecirclebitmap extends bitmaptransformation{
public glidecirclebitmap(context context) {
super(context);
}
// 重寫該方法 返回修改後的bitmap
@override
protected bitmap transform(bitmappool pool, bitmap totransform, int outwidth, int outheight) {
return circlecrop(pool, totransform);
}
@override
public string getid() {
return getclass().getname();
}
private static bitmap circlecrop(bitmappool pool, bitmap source) {
if (source == null) return null;
// 邊長取長寬最小值
int size = math.min(source.getwidth(), source.getheight());
int x = (source.getwidth() - size) / 2;
int y = (source.getheight() - size) / 2;
// todo this could be acquired from the pool too
bitmap squared = bitmap.createbitmap(source, x, y, size, size);
bitmap result = pool.get(size, size, bitmap.config.argb_8888);// argb_4444——代表4x4位argb點陣圖,argb_8888——代表4x8位argb點陣圖
if (result == null) {
result = bitmap.createbitmap(size, size, bitmap.config.argb_8888);
}
canvas canvas = new canvas(result);
paint paint = new paint();
// setshader 對圖像進行渲染
// 子類之一 bitmapshader設置bitmap的變換 tilemode 有clamp (取bitmap邊緣的最後一個像素進行擴展),repeat(水平地重復整張bitmap)
//mirror(和repeat類似,但是每次重復的時候,將bitmap進行翻轉)
paint.setshader(new bitmapshader(squared, bitmapshader.tilemode.clamp, bitmapshader.tilemode.clamp));
paint.setantialias(true);// 抗鋸齒
// 半徑取 size的一半
float r = size / 2f;
canvas.drawcircle(r, r, r, paint);
return result;
}
}
```
```
url url = new ; //將string類型的字元串轉換為url格式
holder.userimage.setimagebitmap(bitmapfactory.decodestream(url.openstream()));
```
```
//得到資源文件的bitmap
bitmap image= bitmapfactory.decoderesource(getresources(),r.drawable.dog);
//創建roundedbitmapdrawable對象
roundedbitmapdrawable roundimg =roundedbitmapdrawablefactory.create(getresources(),image);
//抗鋸齒
roundimg.setantialias(true);
//設置圓角半徑
roundimg.setcornerradius(30);
//設置顯示圖片
imageview.setimagedrawable(roundimg);
```
```
//如果是圓的時候,我們應該把bitmap圖片進行剪切成正方形, 然後再設置圓角半徑為正方形邊長的一半即可
bitmap image = bitmapfactory.decoderesource(getresources(), r.drawable.dog);
bitmap bitmap = null;
//將長方形圖片裁剪成正方形圖片
if (image.getwidth() == image.getheight()) {
bitmap = bitmap.createbitmap(image, image.getwidth() / 2 - image.getheight() / 2, 0, image.getheight(), image.getheight());
} else {
bitmap = bitmap.createbitmap(image, 0, image.getheight() / 2 - image.getwidth() / 2, image.getwidth(), image.getwidth());
}
roundedbitmapdrawable roundedbitmapdrawable = roundedbitmapdrawablefactory.create(getresources(), bitmap);
//圓角半徑為正方形邊長的一半
roundedbitmapdrawable.setcornerradius(bitmap.getwidth() / 2);
//抗鋸齒
roundedbitmapdrawable.setantialias(true);
imageview.setimagedrawable(roundedbitmapdrawable);
```
❻ android怎麼給tablerow添加邊框
總結一下android ui界面裡面如何設置邊框,以及如何把邊框設置成弧形的即圓角。
其實,android的ui里,界面一般都是比較簡單的,不會像web頁面那樣,數據量比較大,關於給android界面(表格)設置邊框,其思想很想我們用html設計表格然後給它設置邊框,如果你懂html的話。即通過給不同的控制項設置背景顏色來反襯出邊框線
以一個登錄界面為例,設置一個有邊框線的android 登錄界面:
註:本例要求的只是將該tablelayout中的行與行之間用邊框線隔開
此例中,採用tablelayout布局,非常簡單,裡面有3個tablerow,分別放置 用戶名、密碼、登錄按鈕,根據上面說的設置邊框線只需要設置控制項的背景顏色即可。這個例子中要求行與行之間有邊框線,那麼,就這么想,
tablelayout:是該界面的布局管理器(當然也是一個控制項),放在最外層,那麼這時你可以給它選一個背景顏色參考注釋 a)
tablerow:是表格中的一行,設置邊框線重點就在此,它是緊跟著tablelayout的,可以給tablerow(行)設置背景色,參考b)
tablelayout與tablerow關系:可以看成父與子的關系,那麼不管怎麼樣,tablelayout總是大於tablerow,那麼通過給二者設置不同的顏色,設置顏色的時候可以讓子組件(tablerow)周圍稍微留出一點邊界(就是它的背景色不會覆蓋完整個行,如何讓它顯示成這樣呢=====>android:layout_margin="0.5dip"[此屬性即是設置該組件周圍留出一點邊界])
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffcccccc" //a)給tablelayout設置背景色,改背景顏色將會是你要設置的邊框線的背景色
android:layout_margin="1dip"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99" //b)給tablerow設置背景色
android:layout_margin="0.5dip" //c)非常重要的一點
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="login name"
android:textstyle="bold"
android:layout_gravity="center_vertical" //如果想讓表格里的列與列(column之間)也有邊框線隔開,則同上面一樣也要設置android:background="#ffffcc99"與android:layout_margin="0.5dip"
>
android:layout_width="141px"
android:layout_height="wrap_content"
android:textsize="18sp"
android:background="#ffffffff"
android:textcolor="#ff000000"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99"
android:layout_margin="0.5dip"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="password"
android:textstyle="bold"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textsize="18sp"
android:background="#ffffffff"
android:textcolor="#ff000000"
>
❼ android怎麼讓button去掉邊框
設置為無背景
android:background="@null"