2017-05-05 3 views
0

Im meinem Projekt habe ich eine Schaltfläche, die so aussieht.Benutzerdefinierte Schaltfläche mit Bildhintergrund und mehrere Textansichten

enter image description here

Ich habe eine benutzerdefinierte Ansicht mit Bildressource als Hintergrund und drei Textansicht erstellt, aber ich habe ein Problem, auf verschiedene Bildschirmgrößen es anders aussieht. Hintergrund streckt sich zu sehr auf großen Bildschirmen und Text ändert seine Position.

Was ist der beste Weg, dies zu tun diese Art von Taste für verschiedene Bildschirmgrößen anpassbar machen.

EDIT

Dies ist xml für meine benutzerdefinierte Ansicht. Der beste Weg, den ich gefunden habe, ist PercentLayout zu verwenden.

<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 patch image ... –

+0

verschiedene Bildgrößen in verschiedenen Zeichnungsordnern speichern (zB hdpi, xxhdpi), Dimensionen auf verschiedenen Dichten unter Wert definieren Ordner in dimens.xml (zB Werte-hdpi, values-xxhdpi) –

+0

Können Sie bitte Ihren XML-Code posten? – FAT

Antwort

0

wenn oben ist Ihre benutzerdefinierte Ansicht, dann sollten Sie Farbe und zeichnen-able xml Datei mit über Form und Verwendung Maße für Höhe und Breite verwenden.

Verwandte Themen