質問

I'm trying to set a transparent button, I create a layout camera and one button overlay the preview, but the button is orbed and I see a square background border. How can get off this border?


<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true"
    android:layout_centerInParent="true">

    <Button
        android:id="@+id/camera_button"
        android:layout_width="90dp"
        android:layout_height="90dp" 
        android:layout_gravity="center"

        />

    <ImageView
        android:contentDescription="@string/camera_button"
        android:background="@android:color/transparent"
        android:layout_width="85dp"
        android:layout_height="85dp"
        android:layout_gravity="center"
        android:scaleType="fitXY"
        android:src="@drawable/camera_buton" />
</FrameLayout>

Thx a lot

役に立ちましたか?

解決 3

Put this element in your button:

android:background="@android:color/transparent"

他のヒント

Try this..

Add android:background="#00000000" to your button element

<Button
        android:id="@+id/camera_button"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:layout_gravity="center"
        android:background="#00000000" />

Make a drawable file to set for background in which fill solid color whatever you want and make stroke color transparent and then set this file as your button bacground.

xml code is somewhat like below code:

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

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

<stroke
    android:width="2dp"
    android:color="@android:color/transparent" />

<corners android:radius="10dp" />

<padding
    android:bottom="5dp"
    android:left="5dp"
    android:right="5dp"
    android:top="5dp" />

</shape>

I believe you are trying to add an image over your button. So that it looks like a camera icon and is clickable as well. (Pardon me if not.)

You should then consider, using ImageButton which exactly does what you want. A Button with a src attribute to set an Image which appears on top of the button.

An example.

Also, incase you wanna show only image but not the border at all, then you can directly use an ImageView which supports click events. :)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top