Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 组合文本和图像按钮,可调整绘图大小_Android_Xml_Android Layout_Resize_Drawable - Fatal编程技术网

Android 组合文本和图像按钮,可调整绘图大小

Android 组合文本和图像按钮,可调整绘图大小,android,xml,android-layout,resize,drawable,Android,Xml,Android Layout,Resize,Drawable,我有一个按钮,我在我的Android项目中的一个活动中实现了这个按钮——这个按钮应该包含一个徽标(一个可绘制的图标)和它后面的一些文本,但我有一个非常奇怪的问题。在我的活动xml文件的预览视图中,按钮看起来非常好,但当我在手机上运行我的应用程序时,它会变得非常大 我从自己制作的.xml drawable导入drawable。我尝试将一个.png直接导入到我的活动中,但它太大了,所以我制作了一个新的xml,在这里我调整了它的大小,而这个xml就是我导入为可绘制的xml。代码: Activity.x

我有一个按钮,我在我的Android项目中的一个活动中实现了这个按钮——这个按钮应该包含一个徽标(一个可绘制的图标)和它后面的一些文本,但我有一个非常奇怪的问题。在我的活动xml文件的预览视图中,按钮看起来非常好,但当我在手机上运行我的应用程序时,它会变得非常大

我从自己制作的.xml drawable导入drawable。我尝试将一个.png直接导入到我的活动中,但它太大了,所以我制作了一个新的xml,在这里我调整了它的大小,而这个xml就是我导入为可绘制的xml。代码:

Activity.xml

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/title_activity_facebookInvite"
    android:id="@+id/btnInviteFacebook"
    android:layout_alignParentBottom="false"
    android:layout_centerHorizontal="true"
    android:layout_below="@+id/mainActivityInviteText"
    android:background="@drawable/bh_red_button"
    android:layout_marginTop="@dimen/bh_input_element_margin"
    android:textSize="@dimen/bh_button_font_size"
    android:drawableLeft="@drawable/fb_resize"
    android:layout_marginLeft="45dp"
    android:layout_marginRight="45dp"
    android:minHeight="0dp" />

fb_resize.xml(我的可绘制文件)



FBU标志是我制作的PNG。另一件非常奇怪的事情是,当我在Android Studio的虚拟设备上模拟它时,它看起来非常好,但在我的手机上却不行(我也试过另一款手机)

看来这就是你的问题:

android:layout_width="fill_parent"
尝试用
wrap\u内容替换
fill\u parent

您也可以尝试在项目中添加以下内容:

 android:scaleType="fitCenter"
 android:adjustViewBounds="true"
好的,这里有一个解决方法,尝试用以下按钮替换您的按钮:

<FrameLayout
    android:id="@+id/NavigateRightButtonLayout"          
    android:layout_below="@+id/mainActivityInviteText"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:layout_marginLeft="45dp"
    android:layout_marginRight="45dp"
    android:gravity="center">
    <Button
     android:textSize="@dimen/bh_button_font_size"
     android:textColor="#FFFFFF"
     android:textAlignment="gravity"
     android:text="@string/title_activity_facebookInvite"
     android:gravity="center"
     android:background="@drawable/bh_red_button"
     android:layout_marginTop="@dimen/bh_input_element_margin"
     android:textSize="@dimen/bh_button_font_size"
     android:layout_gravity="center"
     android:layout_width="match_parent"
     android:layout_height="match_parent"/>
      <ImageView
       android:layout_width="15dp"
       android:layout_height="15dp"
       android:layout_gravity="left"
       android:id="@+id/fb_resizeBtn"
       android:background="@mipmap/fb_logo" />
</FrameLayout>


解决了它!我使用了矢量图片(.svg文件)而不是.png,出于某种原因,它的大小调整得很好

谢谢你的回答,我尝试了你的建议,但没有太大改变-它只是使按钮变窄了一点,但徽标尺寸仍然很大-这不起作用-我真的不明白这怎么会这么难修复。真的很感谢你的努力!不客气^^^如果这一个不起作用,那么我没有主意了。如果这不起作用,您能告诉我们发生了什么以及您的预期结果是什么吗?在尝试您的xml代码后,我可以确认您的drawable fb_resize.xml永远不会遵循宽度和高度参数,而是会占用尽可能多的空间。我不知道为什么现在它不再显示文本或图标,哈哈。这真奇怪。
<FrameLayout
    android:id="@+id/NavigateRightButtonLayout"          
    android:layout_below="@+id/mainActivityInviteText"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:layout_marginLeft="45dp"
    android:layout_marginRight="45dp"
    android:gravity="center">
    <Button
     android:textSize="@dimen/bh_button_font_size"
     android:textColor="#FFFFFF"
     android:textAlignment="gravity"
     android:text="@string/title_activity_facebookInvite"
     android:gravity="center"
     android:background="@drawable/bh_red_button"
     android:layout_marginTop="@dimen/bh_input_element_margin"
     android:textSize="@dimen/bh_button_font_size"
     android:layout_gravity="center"
     android:layout_width="match_parent"
     android:layout_height="match_parent"/>
      <ImageView
       android:layout_width="15dp"
       android:layout_height="15dp"
       android:layout_gravity="left"
       android:id="@+id/fb_resizeBtn"
       android:background="@mipmap/fb_logo" />
</FrameLayout>