简体   繁体   English

按钮大小根据背景图像

[英]Button size according to background image

I am developing an application in which there are many buttons,what I want to do is make the size of button according to background image.我正在开发一个有很多按钮的应用程序,我想做的是根据背景图像制作按钮的大小。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bac"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ttttest.MainActivity" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="37dp"
    android:padding="4dip"
    android:text="Button" />

[![enter image description here][1]][1] [![在此处输入图像描述][1]][1]

image=> https://goo.gl/A1alDZ图像=> https://goo.gl/A1alDZ

Interesting really.真的很有趣。 Never thought of this kind of design.从来没有想过这种设计。 Well I came up with a little something that is very close to what your looking for I believe.好吧,我想出了一些与我相信的您正在寻找的东西非常接近的东西。 Aligning to a background image perfectly is not possible I believe.我相信完全对齐背景图像是不可能的。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:orientation="horizontal"
    android:layout_height="wrap_content">

    <Button
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="match_parent"/>

    <Button
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="match_parent"/>

    <Button
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="match_parent"/>

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="wrap_content">
    <Button
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="match_parent"/>

    <Button
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="match_parent"/>

    <Button
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="match_parent"/>


</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="wrap_content">

    <Button
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="match_parent"/>

    <Button
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="match_parent"/>

    <Button
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="match_parent"/>

</LinearLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM