2016-07-01 11 views
2

私のAndroidプロジェクトのアクティビティの1つに実装されたボタンがあります。ボタンには、ロゴ(ドロウアブル)とそれに続くテキストしかし、私は非常に独特の問題があります。私のアクティビティxml-fileのプレビュービューでは、ボタンは完全にうまく見えますが、自分のアプリケーションを携帯電話で実行すると、ばかばかしくなります。テキストボタンとイメージボタンの組み合わせ、ドロウアブルのサイズ変更

自分が作った.xmlドロアブルからドロアブルをインポートします。私は.pngを直接アクティビティにインポートしようとしましたが、サイズが大きすぎました。サイズを変更する新しい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(マイ描画可能)

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

<item 
    android:id="@+id/fb_resizeBtn" 
    android:drawable="@mipmap/fb_logo" 
    android:width="15dp" 
    android:height="15dp" 
    /> 

</layer-list> 

fb_logoは私が作った私のPNGです。別の非常に奇妙なことは、私はAndroid Studioの仮想デバイスでそれをエミュレートすると、それは完璧には見えますが、私の電話では(別の携帯電話を試してみました。

答えて

1

解決済み! .pngの代わりに、私はベクトル画像(.svgファイル)を使用しましたが、それは何らかの理由でうまくサイズが変更されました。

+1

これまで嬉しいです! –

1

これはあなたの問題であるように見える:

android:layout_width="fill_parent" 

あなたはまた、あなたの商品でこれを追加しようとすることができwrap_content

fill_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> 
+0

あなたのヒントを試してみましたが、実際にはあまり変わっていませんでした。ボタンが少し狭くなりましたが、ロゴのサイズはまだまだ大きいです –

+0

さらにコードが追加されました –

+0

まだ動作しません。どのようにこれを修正するのが難しいかも知れません。あなたの努力に本当に感謝します! –

関連する問題