2013-08-29 2 views
0

Je suis en train de créer une application pour laquelle je souhaite prendre en charge la taille de plusieurs périphériques. Dans mon application, j'utilise un listview pour afficher des données ainsi qu'un adaptateur personnalisé. L'arrière-plan de la liste est une image que j'ai faite. Cette image est essentiellement une largeur de 114heightX700. avec un petit diviseur vertical à environ 1/4 de l'image.Aligner du texte dans ListView personnalisé au format table

Dans le côté gauche, j'ai besoin de centrer les chiffres avec maximum 3 chiffres et à gauche, un titre.

Cela fonctionne très bien sur le Nexus 4, mais si j'essaie d'autres périphériques avec des ppp différents, il ne se centre plus. Existe-t-il un moyen de "découper" le positionnement du texte dans l'image donnée afin qu'il soit toujours à la même position quel que soit le périphérique?

Voici mon XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginLeft="10dp" 
android:layout_marginRight="10dp" 
android:layout_marginTop="10dp" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerInParent="true" 
    android:contentDescription="@string/empty"/> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignBottom="@+id/imageView1" 
    android:layout_alignLeft="@+id/imageView1" 
    android:layout_alignParentTop="true" 
    android:baselineAligned="false" 
    android:orientation="horizontal" > 

    <RelativeLayout 
     android:layout_width="75dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.00" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:text="@string/empty" 
      android:textColor="@android:color/white" 
      android:textSize="18sp" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="0.89" 
     android:paddingLeft="10dp" > 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:lines="1" 
      android:paddingRight="10dp" 
      android:text="@string/empty" 
      android:textColor="@android:color/white" 
      android:textSize="18sp" /> 
    </RelativeLayout> 
</LinearLayout> 

Répondre

0

Il y a 3 options:

  1. Utilisez un LinearLayout mettre tous les enfants à match_parent et définir le layout_weight à 1 pour chaque enfant. Cela amènera tous les enfants à la même taille exacte.
  2. Utilisez un fond 9patch pour chaque enfant. Cela va dessiner votre arrière-plan "autour" du texte.
  3. Utilisez une vue entre le TextView pour afficher le séparateur.

Quoi qu'il en soit: RelativeLayouts/LinearLayout/FrameLayout avec un seul enfant n'a pas de sens. Vous devriez réduire la complexité de votre mise en page.

Questions connexes