导航:首页 > 操作系统 > android自定义边框样式

android自定义边框样式

发布时间:2022-06-29 05:09:24

1. 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>

2. 请问,android上类似美图秀秀一样的给图片添加自定义边框的功能,要怎么实现呢

我也在寻找啊,用canvas画出来的边框不仅代码繁琐而且不美观;
网上有根据assets中的图片资源来添加边框的,但貌似代码没贴全,还是无法实现!
这种问题你在网络知道上问一般是不会有合适的答案的!

3. 怎么给android 设置边框

如果说给控件或则组件加边框,可以使用自定义背景,其中solid是设置填充的,corners是设置边框圆角的,stroke是描边的。下面贴出一段自定义背景。

<selector xmlns:android="http://schemas、android、com/apk/res/android">

<item android:state_selected="true"><shape>
<solid android:color="@color/click_clor" />

<stroke android:width="0dp" />

<corners android:bottomLeftRadius="6dp" android:bottomRightRadius="6dp" android:topLeftRadius="6dp" android:topRightRadius="6dp" />
</shape></item>
<item android:state_focused="true"><shape>
<solid android:color="@color/click_clor" />

<stroke android:width="0dp" />

<corners android:bottomLeftRadius="6dp" android:bottomRightRadius="6dp" android:topLeftRadius="6dp" android:topRightRadius="6dp" />
</shape></item>
<item android:state_pressed="true"><shape>
<solid android:color="@color/click_clor" />

<stroke android:width="0dp" />

<corners android:bottomLeftRadius="6dp" android:bottomRightRadius="6dp" android:topLeftRadius="6dp" android:topRightRadius="6dp" />
</shape></item>
<item android:state_enabled="false"><shape>
<solid android:color="@color/top_color" />

<stroke android:width="0dp" />

<corners android:bottomLeftRadius="6dp" android:bottomRightRadius="6dp" android:topLeftRadius="6dp" android:topRightRadius="6dp" />
</shape></item>
<item><shape>
<solid android:color="@color/top_color" />

<stroke android:width="0dp" />

<corners android:bottomLeftRadius="6dp" android:bottomRightRadius="6dp" android:topLeftRadius="6dp" android:topRightRadius="6dp" />
</shape></item>

</selector> 将此新建放入drawable文件夹
使用很简单
直接background="@drawable/文件名"即可

4. 怎么给android 设置边框

边框主要是使用shape文件,可以定制左右上下的边框,如果想要隐藏某部分,设置我透明即可。

5. 怎么给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自定义边框样式相关的资料

热点内容
战双程序员 浏览:479
him触摸编程软件 浏览:929
植物大战僵尸存档怎么转移安卓 浏览:852
java栈的元素 浏览:737
程序员与篮球事件 浏览:675
app反编译不完整 浏览:788
电脑上的文件夹怎么调整 浏览:7
服务器无响应是什么原因呀 浏览:984
wd文档里的app怎么制作 浏览:513
电脑里的文件夹没有了一般能恢复吗 浏览:418
哪里有配加密钥匙的 浏览:210
服务器开不了机怎么把数据弄出来 浏览:958
gif动态图片怎么压缩 浏览:521
黑猴子棒球压缩文件解压密码 浏览:631
如何让app适应不同的手机屏幕大小 浏览:10
苹果手机如何给安卓手机分享软件 浏览:761
苹果电脑怎么运行腾讯云服务器 浏览:59
明日之后沙石堡命令助手 浏览:261
蛋糕店用什么样的app 浏览:877
长安银行信用卡app怎么取现 浏览:635