2017-05-05 86 views
0

我的項目我有一個按鈕,看起來像這樣。圖像背景和多個文本視圖的自定義按鈕

enter image description here

我已創建了圖片資源爲背景,三個文本視圖自定義視圖,但我有一個問題,在不同的屏幕尺寸看起來不同。背景在大屏幕和文本更改位置上延伸太多。

什麼是最好的方法來做這種按鈕,使其適應不同的屏幕尺寸。

編輯

這是我的自定義視圖的xml。我發現這樣做的最好方法是使用PercentLayout。

<android.support.percent.PercentFrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
> 
<ImageView 
    android:id="@+id/background_image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/blue_button" /> 

<TextView 
    android:id="@+id/custom_button_main_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="@dimen/custom_button_text_left_margin" 
    app:layout_marginTopPercent="12%" 
    android:textSize="@dimen/custom_button_title_text_size" 
    android:textColor="@android:color/white" 
    /> 

<TextView 
    android:id="@+id/custom_button_additional_left_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:layout_marginTopPercent="70%" 
    app:layout_marginLeftPercent="20%" 
    android:textSize="@dimen/custom_button_additional_text_size" 
    android:textColor="@android:color/black" 
    /> 

<TextView 
    android:id="@+id/custom_button_additional_right_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:layout_marginTopPercent="70%" 
    app:layout_marginLeftPercent="80%" 
    android:textSize="@dimen/custom_button_additional_text_size" 
    android:textColor="@android:color/black" 
    /> 

+0

9修補圖像... –

+0

在不同的可繪製文件夾(例如hdpi,xxhdpi)中保留不同密度大小的圖像,在dimens.xml中的值文件夾下定義不同密度下的維(例如values-hdpi,values-xxhdpi) –

+0

你可以請張貼你的xml代碼嗎? – FAT

回答

0

如果上面是你的自定義視圖,那麼你應該使用的顏色和畫,能xml文件,上述形狀和使用尺寸的高度和寬度。