/ / Taille et position relatives de ImageButton - Android

Taille et position relatives de ImageButton - Android

J'essaye de faire grimper un ImageButton pour s'adapter à 50% de la largeur de l'écran et le centrer horizontalement, quelles que soient la taille de l'image d'origine ou la taille de l'écran du périphérique. Cette image décrit plus précisément le résultat final que je recherche.

Toute aide serait très appréciée. Je vous remercie.

Réponses:

0 pour la réponse № 1

L’une des façons d’obtenir l’effet recherché est d’utiliser le weight attribut des enfants d'un LinearLayout combiné avec 2 invisible Views cela agira comme un rembourrage de 25% de chaque côté. Sérieusement, cependant, votre question aurait pu être bien meilleure. Veuillez lire les directives de publication de SO pour la prochaine fois.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="20dp">


<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:visibility="invisible"/>

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:layout_weight="0.5"
android:orientation="vertical">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:visibility="invisible"/>
</LinearLayout>