導航:首頁 > 操作系統 > android表格邊框

android表格邊框

發布時間:2022-05-19 08:12:38

android TableRow加邊框

應該是父布局的寬度有問題,你看看設置tablerower設置成一個固定的寬度看看.

Ⅱ 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怎麼給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"[此屬性即是設置該組件周圍留出一點邊界])
<?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="http://schemas.android.com/apk/res/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>

Ⅳ 怎麼給android 設置邊框

  1. android設置邊框利用內容的margin或者padding的留白加容器的背景來實現邊框效果。

  2. shape來實現邊框效果

  3. corners是設置邊框圓角

  4. stroke是描邊的

  5. layer-list實現自由邊框

嵌套一層,利用內容的margin或者padding的留白加容器的背景來實現邊框效果。其實這個道理很簡單,很早的時候那時候我們還用table做html頁面布局的時候,我們就是使用cellspacing來實現table的邊框的。現在我們也利用同樣的想法來實現。

當然內部的容器也是需要有顏色的,如果想實現內部透明的效果則需要將內部View的背景色跟背景的顏色保持一致,這是不太方便的地方。


在Android中,給一個控制項(或View)設置背景主要是通過background:xxx屬性來完成。background的參數一般來說是一個drawable資源。


給控制項設置邊框最簡單的方式就是把background設置成你預先設計好的帶圓角和邊框的背景圖。但是這種方法的缺點是沒有靈活性,不同大小的view要不同尺寸的圖片,還要去適應不同解析度的設備。


3使用9-patch(九宮格)的背景圖片來實現邊框效果。


做一個有邊框的9-patch圖片,作為要有邊框的View的背景圖即可。這樣你還可以控制哪邊有邊框,哪邊無邊框,這種方法是比較好的一種方法,而且沒有多餘的View嵌套。另外你還可以實現圓角邊框等效果。


4利用shape來實現邊框效果。


當然你可以使用shape中的stroke來實現border的效果。


/res/drawable/filename.xml


只要引用這個shape作為背景圖片即可。


5.layer-list實現自由邊框

當前版本的Android

SDK並沒有給stroke提供bottom、left、right之類的屬性,也就是說你無法通過它來讓長方形的邊框少於4條。於是有人想出了這個方法。


android:width="1dp"


android:color="#333"/>


android:left="1dp"


android:top="1dp"


android:right="1dp"


android:bottom="1dp">


android:color="#FFF"/>


在第二個item中定義的top,left...就是對應的邊框,不設置即沒有邊框。

Ⅳ android表格布局如何添加excel邊框 求代碼,求圖,謝謝各位大俠!

Ⅵ 怎麼給android 設置邊框

Android控制項設置邊框的該如下:
1. 在drawable新建一個 buttonstyle.xml的文件,內容如下:
<?xml vers
ion="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 連框顏色值 --><item>
<shape>
<solid android:color="#ff0000" />
</shape>
</item>
<!-- 主體背景顏色值 -->
<item android:bottom="3dp" android:right="3dp">
<shape>
<solid android:color="#ffffff" />
<padding android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
</item>
</layer-list>

2.然後在布局文件裡面引入這個xml,示例代碼如下:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1"
android:background="@drawable/buttonstyle" />

Ⅶ android怎麼讓gridview有邊框線

gridview有邊框線通過設置裡面控制項的backgroud,也就是邊框。通過shape設置。

下面例子來自於android學習手冊,android學習手冊包含9個章節,108個例子,源碼文檔隨便看,例子都是可交互,可運行, 源碼採用android studio目錄結構,高亮顯示代碼,文檔都採用文檔結構圖顯示,可以快速定位。360手機助手中下載,圖標上有貝殼。

java"><?xmlversion="1.0"encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android">

<!--圓角-->
<corners
android:radius="9dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:bottomRightRadius="2dp"/><!--設置圓角半徑-->

<!--漸變-->
<gradient
android:startColor="@android:color/white"
android:centerColor="@android:color/black"
android:endColor="@android:color/black"
android:useLevel="true"
android:angle="45"
android:type="radial"
android:centerX="0"
android:centerY="0"
android:gradientRadius="90"/>

<!--間隔-->
<padding
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/><!--各方向的間隔-->

<!--大小-->
<size
android:width="50dp"
android:height="50dp"/><!--寬度和高度-->

<!--填充-->
<solid
android:color="@android:color/white"/><!--填充的顏色-->

<!--描邊-->
<stroke
android:width="2dp"
android:color="@android:color/black"
android:dashWidth="1dp"
android:dashGap="2dp"/>

</shape>

Ⅷ 怎麼實現一個布局頁面中的表格邊框

這樣定義就有邊框了:

android:layout_width="fill_parent"
android:layout_height="fill_parent" >

android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textSize="15px" />

android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textSize="15px" />

Ⅸ 怎麼給android 設置邊框

邊框主要是使用shape文件,可以定製左右上下的邊框,如果想要隱藏某部分,設置我透明即可。

Ⅹ android的PopupWindow怎麼添加邊框

popUpWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.page2));
設置的是popupwindow(window容器)的背景。
popUpWindow = new PopupWindow(show_popvieView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); //是將show_popvieView放入容器中,以自適應作為大小,且容器也採用自適應。
綜上,如果你設置大小,導致show_popvieView沾滿整個屏幕,那麼window容器最為底層,設置的背景坑定是看不見的。
建議:背景設置採用設置show_popvieView的背景。如果有多層,可以在內容裡面鑲嵌,最好別直接設置外層popupwindow容器

閱讀全文

與android表格邊框相關的資料

熱點內容
郵件附件加密後打開能顯示嗎 瀏覽:721
榮耀x10拍照演算法 瀏覽:567
androidgradle配置簽名 瀏覽:92
文件夾左邊的空心三角符號是什麼 瀏覽:284
app英語音頻試卷掃碼怎麼聽 瀏覽:613
字元串編譯預處理 瀏覽:703
蘋果手機怎麼會顯示多個App 瀏覽:240
不去互聯網程序員 瀏覽:553
電腦qq郵箱解壓的圖片保存在哪裡 瀏覽:546
嵌入命令行 瀏覽:92
檔案為什麼被加密 瀏覽:487
十天學會單片機13 瀏覽:875
榮耀怎麼設置讓app一直運行 瀏覽:994
共享文件夾能在哪裡找到 瀏覽:435
旅遊訂旅店用什麼app 瀏覽:241
一個女程序員的聲音 瀏覽:497
魔術app怎麼用 瀏覽:340
單片機有4個8位的io口 瀏覽:898
win10rar解壓縮軟體 瀏覽:170
plc教程pdf 瀏覽:668