當前位置:首頁 » 安卓系統 » androidlayout邊框

androidlayout邊框

發布時間: 2024-09-16 11:18:24

『壹』 android中GridView的顯示圖片邊框

用ImageView裡面,如果是在xml裡面就設置一個android:padding="4dip"這樣就可以了,如果是在java裡面,那就設置一下ImageView.setPadding(4,4,4,4);這樣就可以了,我也糾結了好久,其實是自己對這個東西不太熟悉

『貳』 請問這個android界面用到了什麼布局,還有那些邊框,是怎麼畫出來的。

每一個用Linerlayout就行,至於圓角框樣式用xml配置一下,裡面的橫線imageView畫一下就行
這有個例子,效果不一樣,你可以試著調一下裡面的參數
drawable/ table_shape.xml

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

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

//設置邊距
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />

//控制邊界線顏色和筆觸大小
<stroke
android:width="1dp"
android:color="#CdCdCd" />

//控制界面顏色漸變(你這個用不到)
<gradient
android:startColor="#E9E9E9"
android:endColor="#FFFFFF"
android:type="linear"
android:angle="90"/>

//控制圓角大小
<corners android:radius="10dp" />

</shape>

然後在Linerlayout里設置android:background="@drawable/table_shape"
就行啦!

『叄』 android設置控制項樣式(邊框顏色,圓角)和圖片樣式(圓角)

本文鏈接:https://blog.csdn.net/weixin_37577039/article/details/79090433

```

<?xml version="1.0" encoding="utf-8"?>

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

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

    <!-- 這里是設置為四周 也可以單獨設置某個位置為圓角-->

    <corners android:topLeftRadius="5dp"

        android:topRightRadius="5dp"

        android:bottomRightRadius="5dp"

        android:bottomLeftRadius="5dp"/>

    <stroke android:width="1dp" android:color="#000000" />

</shape

```

```
<?xml version="1.0" encoding="UTF-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">   

<!-- 邊框顏色值 -->

<item>   

      <shape>   

            <solid android:color="#3bbaff" />   

      </shape>   

</item>   

<!--這個是按鈕邊框設置為四周 並且寬度為1-->

<item

android:right="1dp"

android:left="1dp"

android:top="1dp"

android:bottom="1dp">

    <shape>   

<!--這個是背景顏色-->

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

<!--這個是按鈕中的字體與按鈕內的四周邊距-->

          <padding android:bottom="10dp"   

                android:left="10dp"   

                android:right="10dp"   

                android:top="10dp" />   

    </shape>       

</item>   

</layer-list>

```

使用:

```android:background="@drawable/button_edge"```

```
<?xml version="1.0" encoding="UTF-8"?>

<shape

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:shape="rectangle">

    <!-- 填充的顏色 -->

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

    <!-- android:radius 弧形的半徑 -->

    <!-- 設置按鈕的四個角為弧形 -->

    <corners

    android:radius="5dip" /> 

    <!--也可單獨設置-->

    <!-- <corners -->

  <!-- android:topLeftRadius="10dp"-->

  <!-- android:topRightRadius="10dp"-->

  <!-- android:bottomRightRadius="10dp"-->

  <!--  android:bottomLeftRadius="10dp"-->

<!--  />  -->

        **設置文字padding**

    <!-- padding:Button裡面的文字與Button邊界的間隔 -->

    <padding

        android:left="10dp"

        android:top="10dp"

        android:right="10dp"

        android:bottom="10dp"

        />

</shape>

```

```
<?xml version="1.0" encoding="utf-8"?>

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

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

    <corners android:topLeftRadius="10dp"

        android:topRightRadius="10dp"

        android:bottomRightRadius="10dp"

        android:bottomLeftRadius="10dp"/>

</shape>

```

使用:

```

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 URL(String類型的字元串); //將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 怎麼繪製表格邊框

一、表格最蛋疼的就是那根線,網上有個很好的方法,大概思路是這樣的:
1、給表格設置一個背景色(線的顏色)
2、給表格設置一個內邊距(線的寬度的一半)
3、設置每一項內邊距(線的寬度的一半)
3、給項的內容設置一個背景色(顏色不同於線即可)
顯示效果大概是這樣的:
二、數據的動態載入使用Adapter類,便與布局載入
自定義TableLayout載入的主體方法:
public void setAdapter(BaseAdapter baseAdapter, int column) {
if (baseAdapter == null || baseAdapter.getCount() == 0) {
return;
}
this.mAdapter = baseAdapter;
this.column = column;
drawLayout();
}

private void drawLayout() {
removeAllViews();
int realcount = mAdapter.getCount();
int count = 0;
if (realcount < column) {
count = column;
} else if (realcount % column != 0) {
count = realcount + column - (realcount % column);
} else {
count = realcount;
}
TableRow tableRow = null;//每一行的TableRow
for (int i = 0; i < count; i++) {
final int index = i;
View view = null;
if (index >= realcount) {
view = mAdapter.getView((realcount - 1), null, null);
view.setVisibility(View.INVISIBLE);
} else {
view = mAdapter.getView(index, null, null);
}
if (index % column == 0) {// 整行
tableRow = new TableRow(mContext);
}
if (tableRow != null) {//添加每一個Item
tableRow.addView(view);
}
if (index % column == 0) {// 整行
addView(tableRow, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
}
}

三、使用和ListView的方式基本一樣
public class MainActivity extends Activity {
private List<Map<String, Object>> dataList;
private TableBorderLayout layTable;
private String[] datas = new String[] { "瘋狂", "個性", "張揚", "抖擻", "加油", "奮斗",
"努力", "精神" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
loadDatas();
}
private void initViews() {
layTable = (TableBorderLayout) findViewById(R.id.layTable);
}
private void loadDatas() {
dataList = new ArrayList<Map<String, Object>>();
Map<String, Object> item = null;
for (int i = 0; i < datas.length; i++) {
item = new HashMap<String, Object>();
item.put("Title", datas[i]);
dataList.add(item);
}
layTable.setAdapter(new MyAdapter(this, dataList));
}
}

『伍』 怎麼給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"[此屬性即是設置該組件周圍留出一點邊界])
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout
android:id="@+id/widget30"
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:background="@drawable/view_shape" -->
<TableRow
android:id="@+id/widget40"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99" //b)給tablerow設置背景色
android:layout_margin="0.5dip" //c)非常重要的一點
>
<TextView
android:id="@+id/widget41"
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"
>
</TextView>
<EditText
android:id="@+id/widget42"
android:layout_width="141px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:background="#ffffffff"
android:textColor="#ff000000"
>
</EditText>
</TableRow>
<TableRow
android:id="@+id/widget43"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99"
android:layout_margin="0.5dip"
>
<TextView
android:id="@+id/widget44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textStyle="bold"
>
</TextView>
<EditText
android:id="@+id/widget45"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:background="#ffffffff"
android:textColor="#ff000000"
>
</EditText>
</TableRow>
<Button
android:id="@+id/widget46"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textStyle="bold"
android:textColor="#ff000000"
android:layout_margin="2dip"
android:background="#ffffcc33"
>
<!--android:background="@drawable/view_shape" -->
</Button>
</TableLayout>

熱點內容
海康威視存儲卡質量如何 發布:2024-09-19 08:55:35 瀏覽:938
python3默認安裝路徑 發布:2024-09-19 08:50:22 瀏覽:514
環衛視頻拍攝腳本 發布:2024-09-19 08:35:44 瀏覽:416
sqlserveronlinux 發布:2024-09-19 08:16:54 瀏覽:255
編程常數 發布:2024-09-19 08:06:36 瀏覽:951
甘肅高性能邊緣計算伺服器雲空間 發布:2024-09-19 08:06:26 瀏覽:161
win7家庭版ftp 發布:2024-09-19 07:59:06 瀏覽:716
資料庫的優化都有哪些方法 發布:2024-09-19 07:44:43 瀏覽:268
知乎華為編譯器有用嗎 發布:2024-09-19 07:32:20 瀏覽:617
訪問虛擬機磁碟 發布:2024-09-19 07:28:13 瀏覽:669