我正试图在Android ImageButton上转角,代码看起来像这样;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:layout_marginTop="57dp"
android:src="@drawable/friends"
android:padding="1dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/imageButton2"
android:layout_marginRight="62dp" />
</RelativeLayout>
</LinearLayout>
基本上我们的输出是一个ImageButton,但它有方角,我们正试图圆角。
由于
答案 0 :(得分:47)
在android中使用Shape来制作圆角
创建名为roundcorner.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#33DDFF" />
<corners android:radius="4dp" />
</shape>
在图片按钮中添加此属性android:background="@drawable/roundcorner"
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:layout_marginTop="57dp"
android:src="@drawable/friends"
android:background="@drawable/roundcorner"
android:padding="1dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/imageButton2"
android:layout_marginRight="62dp" />
答案 1 :(得分:9)
您可以使用由形状绘制的选择器作为背景,例如:
rounded_bg.xml(在res / drawable-nodpi文件夹中创建)
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffffff" />
<corners
android:bottomLeftRadius="4dp"
android:bottomRightRadius="4dp"
android:topLeftRadius="4dp"
android:topRightRadius="4dp" />
</shape>
创建另一个,更改solid android:color="#ffffff"
中引用的颜色,例如更改为solid android:color="#ff0000"
,并将该文件命名为rounded_bg_selected.xml
创建选择器(也在res / drawable-nodpi中),将其命名为selectable_button_bg.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/rounded_bg_selected" />
<item android:state_focused="false"
android:drawable="@drawable/rounded_bg" />
</selector>
然后在你的布局中引用它:
<ImageButton
android:background="@drawable/selectable_button_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:layout_marginTop="57dp"
android:src="@drawable/friends"
android:padding="1dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/imageButton2"
android:layout_marginRight="62dp" />
答案 2 :(得分:5)
在/ res / drawable
中创建image_rounded_corner.xml
<?xml version="1.0" encoding="UTF-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#000000" />
<stroke android:width="3dp" android:color="#776da8" />
<corners android:bottomRightRadius="5dp" android:bottomLeftRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" />
<padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp" />
</shape>
使用android:background
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myimage"
android:src="@drawable/icon"
android:background="@drawable/image_rounded_corner" />
或使用Draw 9-patch文件作为“Artoo Detoo”建议。
答案 3 :(得分:4)
使用此: 把它放在res / drawable文件夹中
<强> my_gradient.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="100dp" />
<stroke
android:width="5dp"
android:color="#090" />
</shape>
在你的ImageButton中只需输入:
android:background="@drawable/my_gradient"
答案 4 :(得分:0)
if(isset($_FILES['file']) && !empty($_FILES['file']['name'])){
$filename = basename($_FILES['file']['name']);// i am not getting value here
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$new_name= md5($filename.time()).'.'.$extension;
$update = mysql_query("UPDATE task_employee SET emp_lastname='$lstname',emp_main_photo = '$new_name' WHERE emp_id='".$_SESSION['emp_id']."'");
}else{
$update = mysql_query("UPDATE task_employee SET emp_lastname='$lstname' WHERE emp_id='".$_SESSION['emp_id']."'");
}
此代码可以为您提供帮助。(来自中文文章:http://www.cnblogs.com/liuweiming/archive/2012/04/23/2466074.html)