安卓:对齐图像按钮的右上角 [英] Android : Align image on top right hand corner of button

查看:173
本文介绍了安卓:对齐图像按钮的右上角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它看起来像一个复选框,我想对齐按钮,右上角的图像。试过相对布局,但不能达到预期的效果。任何建议来实现所需的结果

I have an image which looks like a checkbox, that i would like to align on top right hand corner of button. Have tried relative layout but could not achieve desired result. Any suggestion to achieve the desired result?

我一直使用的FrameLayout尝试,但在checbox图像仍然隐藏

I have tried using Framelayout but the checbox image remains hidden

 <FrameLayout 
         android:layout_marginLeft="10dp"
        android:layout_marginTop="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">


        <ImageView 
            android:id="@+id/filter_check"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:background="@drawable/checkmark"
             android:layout_gravity="right"
            />

         <Button
            android:id="@+id/filter"
            style="@style/Widget.Button.White.BlueText.BlueStroke"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Filter" />


    </FrameLayout>

在图像之前法鲁克的建议使用按钮。这里是code

After Farouk's suggestions to use Button before image. Here is the code

<FrameLayout 
     android:layout_marginLeft="10dp"
    android:layout_marginTop="20dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <Button
        android:id="@+id/filter"
        style="@style/Widget.Button.White.BlueText.BlueStroke"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Filter" />

      <ImageView 
        android:id="@+id/filter_check"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:background="@drawable/checkmark"
         android:layout_gravity="top|right"
        />

</FrameLayout>

下面是我的设计师看到的。

Here is what i see on designer.

不知道如何将复选框图像向上和向右。

Not sure how to move the checkbox image up and right.

如果你想要的解决方案,那就是:

<FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="80dp" >

        <Button
            android:id="@+id/filter"
            style="@style/Widget.Button.White.BlueText.BlueText.FrameImage"
            android:layout_margin="10dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Sort" />

        <ImageView
            android:id="@+id/widget_title_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top|right"
            android:src="@drawable/checkmark" />
    </FrameLayout>


  <style name="Widget.Button.White.BlueText.BlueText.FrameImage" parent="@android:style/Widget.Button">
        <item name="android:background">@drawable/white_button_blue_stroke_bg_selector</item>
        <item name="android:gravity">center</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
    </style>

解决方法:

推荐答案

这看起来是这样的:

刚刚与机器人玩:paddingTop = - 10dp只要你喜欢

Just play with the android:paddingTop="-10dp" as you like.

下面的code:

    <Button
        android:id="@+id/filter"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="7dp"
        android:background="#0000FF"
        android:gravity="center"
        android:paddingBottom="25dp"
        android:paddingTop="25dp"
        android:text="Sort"
        android:textColor="#FFFFFF" />

    <ImageView
        android:id="@+id/widget_title_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|right"
        android:adjustViewBounds="true"
        android:paddingTop="-10dp"
        android:scaleType="fitStart"
        android:src="@drawable/checkbtn" />

</FrameLayout>

这篇关于安卓:对齐图像按钮的右上角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆