Android 按钮位于背景图像之外
我想我找不到标题的正确单词,所以我会尝试正确解释 因此,我将此图像作为布局的背景: 我希望按钮能正确安装 因为在左边和右边都有一些透明度。 因此,按钮超出了表的范围 有什么可以说“嘿,这是透明的,我不想要任何东西”的吗? 或者“嘿,这就是我想把所有东西都放的地方?” 我试着把另一个线性布局,但我不知道如何给好的宽度Android 按钮位于背景图像之外,android,android-layout,Android,Android Layout,我想我找不到标题的正确单词,所以我会尝试正确解释 因此,我将此图像作为布局的背景: 我希望按钮能正确安装 因为在左边和右边都有一些透明度。 因此,按钮超出了表的范围 有什么可以说“嘿,这是透明的,我不想要任何东西”的吗? 或者“嘿,这就是我想把所有东西都放的地方?” 我试着把另一个线性布局,但我不知道如何给好的宽度 谢谢如果您使用的是线性布局,您可以为图像设置背景。然后您可以将任何内容放入线性布局中,所有内容都将正确放入图像中 例如: <?xml version="1.0" encodi
谢谢如果您使用的是
线性布局
,您可以为图像设置背景。然后您可以将任何内容放入线性布局
中,所有内容都将正确放入图像中
例如:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="320dp"
android:layout_height="512dp"
android:background="@drawable/scaled"
android:orientation="vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:text="Button" />
</LinearLayout>
希望有帮助。如果您使用的是
线性布局
,您可以为图像设置背景。然后您可以将任何内容放入线性布局
中,所有内容都将正确地放入图像中
例如:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="320dp"
android:layout_height="512dp"
android:background="@drawable/scaled"
android:orientation="vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:text="Button" />
</LinearLayout>
希望能有所帮助。这是我代码的一部分:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/fond"
>
<ImageView
android:id="@+id/imageView1"
android:contentDescription="@string/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/top"
android:layout_gravity="top"
android:adjustViewBounds="true"
/>
<LinearLayout
android:layout_below="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/fond1"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3"
>
<Button
android:id="@+id/button_garçon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bg"
android:background="@drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionGarçon"
/>
<Button
android:id="@+id/button_mixte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bm"
android:background="@drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionMixte"
/>
<Button
android:id="@+id/button_fille"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bf"
android:background="@drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionFille"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
这是我代码的一部分:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/fond"
>
<ImageView
android:id="@+id/imageView1"
android:contentDescription="@string/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/top"
android:layout_gravity="top"
android:adjustViewBounds="true"
/>
<LinearLayout
android:layout_below="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/fond1"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3"
>
<Button
android:id="@+id/button_garçon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bg"
android:background="@drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionGarçon"
/>
<Button
android:id="@+id/button_mixte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bm"
android:background="@drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionMixte"
/>
<Button
android:id="@+id/button_fille"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bf"
android:background="@drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionFille"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
从您的问题中,我了解到您希望避免将按钮放在背景图像的左右透明边缘。您可以使用
android:layout\u marginLeft
和android:layout\u marginRight
进行此操作。对于您的代码,类似以下内容:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/fond"
>
<ImageView
android:id="@+id/imageView1"
android:contentDescription="@string/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/top"
android:layout_gravity="top"
android:adjustViewBounds="true"
/>
<LinearLayout
android:layout_below="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/fond1"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp" <!--Use the correct dp value, i just use it for example -->
android:layout_marginRight="30dp" <!--Use the correct dp value, i just use it for example -->
android:weightSum="3"
>
<Button
android:id="@+id/button_garçon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bg"
android:background="@drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionGarçon"
/>
<Button
android:id="@+id/button_mixte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bm"
android:background="@drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionMixte"
/>
<Button
android:id="@+id/button_fille"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bf"
android:background="@drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionFille"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
android:layout_marginRight=“30dp”
android:weightSum=“3”
从您的问题中,我了解到您希望避免将按钮放在背景图像的左右透明边缘。您可以使用android:layout\u marginLeft
和android:layout\u marginRight
进行此操作。对于您的代码,类似以下内容:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/fond"
>
<ImageView
android:id="@+id/imageView1"
android:contentDescription="@string/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/top"
android:layout_gravity="top"
android:adjustViewBounds="true"
/>
<LinearLayout
android:layout_below="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/fond1"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp" <!--Use the correct dp value, i just use it for example -->
android:layout_marginRight="30dp" <!--Use the correct dp value, i just use it for example -->
android:weightSum="3"
>
<Button
android:id="@+id/button_garçon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bg"
android:background="@drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionGarçon"
/>
<Button
android:id="@+id/button_mixte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bm"
android:background="@drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionMixte"
/>
<Button
android:id="@+id/button_fille"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bf"
android:background="@drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionFille"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
android:layout_marginRight=“30dp”
android:weightSum=“3”
我输入了我的代码。你的答案没有帮助,因为图像的左右两侧都有透明度,所以按钮位于透明度区域,我希望它们位于“工作表”区域“希望你明白我的意思。看看我的编辑,也许这就是你要找的。你最好编辑他的。”。但是Angelo做了一些更适合我尝试做的事情(几乎是一样的事情)。我把我的代码。你的回答没有帮助,因为图像的左右两侧都有透明度,所以按钮位于透明度区域,我希望它们位于“工作表区域”,希望你理解我的意思。看看我的编辑,也许这就是你要找的。你最好编辑他。但是Angelo做了一些更适合我尝试做的事情(几乎是一样的事情)。它在AVD上正确匹配,但在所有使用此解决方案的手机上都可以?@user1527152这取决于手机的分辨率和屏幕大小。但是如果你提供了一个令人满意的dp值,我想你会没事的。我没有看到它,但它会改变我的按钮的大小:/是的,它会改变你的按钮的大小(宽度),因为你在按钮中使用了布局重量。我认为对你来说,这是不可避免的。顺便说一句,在你的按钮中添加android:layout\u width=“0dp”
而不是android:layout\u width=“wrap\u content”
,我认为这样更好,因为你在按钮中使用了权重。我尝试了一些东西,我想我不会有更好的答案。谢谢你帮我解决了整个下午的这两个问题,所以现在下午5:30我保存了所有东西并停止了工作。再次感谢。它在AVD上安装正确,但在使用此解决方案的所有手机上都可以?@user1527152这取决于手机的分辨率和屏幕大小。但是如果你提供了一个令人满意的dp值,我想你会没事的。我没有看到它,但它会改变我的按钮的大小:/是的,它会改变你的按钮的大小(宽度),因为你在按钮中使用了布局重量。我认为对你来说,这是不可避免的。顺便说一句,在你的按钮中添加android:layout\u width=“0dp”
而不是android:layout\u width=“wrap\u content”
,我认为这样更好,因为你在按钮中使用了权重。我尝试了一些东西,我想我不会有更好的答案。谢谢你帮我解决了整个下午的这两个问题,所以现在下午5:30我保存了所有东西并停止了工作。再次感谢。