调整图像大小按钮

发布于 2024-12-19 04:56:02 字数 1120 浏览 3 评论 0 原文

我有一个放置图片的按钮...我必须尝试调整按钮内图像的大小...如何调整它的大小?我可以直接从xml代码中做到这一点吗? 这是 xml 代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layout_root"
        android:orientation="vertical"
        android:layout_width="250dp"
        android:layout_height="180dp"
        android:paddingLeft="4dip"
        android:paddingRight="4dip"
        android:background="@color/white_trasparent"
        android:weightSum="1">

    <TextView 
        android:layout_height="wrap_content" 
        android:id="@+id/text" 
        android:textColor="@color/grey" 
        android:textAppearance="?android:attr/textAppearanceLarge" 
        android:layout_width="wrap_content" 
        android:layout_marginLeft="15dp">
        </TextView>
    <Button 
        android:layout_width="wrap_content" 
        android:text="Drawable Top" 
        android:id="@+id/Button03" 
        android:drawableTop="@drawable/icon" 
        android:layout_height="wrap_content" 
        android:textSize="10dp">
        </Button>
</LinearLayout>

I have a button where I put a picture ... I must try to resize the image inside the button ... how can I resize it? Can I do it directly from the xml code?
This is the xml code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layout_root"
        android:orientation="vertical"
        android:layout_width="250dp"
        android:layout_height="180dp"
        android:paddingLeft="4dip"
        android:paddingRight="4dip"
        android:background="@color/white_trasparent"
        android:weightSum="1">

    <TextView 
        android:layout_height="wrap_content" 
        android:id="@+id/text" 
        android:textColor="@color/grey" 
        android:textAppearance="?android:attr/textAppearanceLarge" 
        android:layout_width="wrap_content" 
        android:layout_marginLeft="15dp">
        </TextView>
    <Button 
        android:layout_width="wrap_content" 
        android:text="Drawable Top" 
        android:id="@+id/Button03" 
        android:drawableTop="@drawable/icon" 
        android:layout_height="wrap_content" 
        android:textSize="10dp">
        </Button>
</LinearLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏璃陌 2024-12-26 04:56:02

如果我对drawableTop/left/bottom/right属性的理解是正确的,那么不会将您的图像放置在按钮内,而是将其放置在按钮的顶部(北部)。

如果您想将图像放入按钮中,请查看 ImageButton

我认为这些东西都不会让你只设置图像的大小(它们会让你改变整个视图的大小,在这种情况下是矩形按钮框,以及其中的图像。

)为了改变图像的大小而不影响按钮框图形的大小我认为你必须在 Photoshop 或其他东西中缩小你的资源图像。

if my understanding of the drawableTop/left/bottom/right properties is correct that is not going to place your image inside your button, rather it is going to put it on top (north of) your button.

If you're looking to put an image inside a button check out ImageButton.

I don't think either of these things will let you just set the size of only your image though (they will let you change the size of the whole view, in this case the rectangle button box, and the image inside it.)

In order to change the size of the image without affecting the size of the button box graphic I think you'd have to shrink your resource image in photoshop or something.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文