0

写真のように、中央の固定位置合わせを行う必要があります。

http://postimage.org/image/t735us1z3/

したがって、2つのTextViewが左右に拡大している間、旗の画像は常に中央にあります。したがって、テキストがどれだけ長くなっても、画像は中央に表示されます。さらに、中央に「vs」TextViewがあります。

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
 >

<TextView android:id="@+id/list_item_entry_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
         />



     <ImageView 
        android:id="@+id/flag1"
        android:layout_width="20dp"
        android:layout_height="20dp"   
        android:layout_marginLeft="5dp" 
        android:layout_marginRight="5dp" 
        android:src="@drawable/bayern25"
        android:layout_marginTop="5dp" 
      android:layout_toRightOf="@+id/list_item_entry_title"
        />

       <TextView android:text="-"
             android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
         android:layout_toRightOf="@+id/flag1"
         />


       <ImageView 
        android:id="@+id/flag2"
        android:layout_width="20dp"
        android:layout_height="20dp"  
        android:layout_marginLeft="5dp"  
          android:layout_marginTop="5dp" 
        android:src="@drawable/wolfsburg25"
        android:layout_toRightOf="@+id/text"
        />


     <TextView android:id="@+id/list_item_entry_summary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/list_item_entry_title"
        android:layout_alignLeft="@id/list_item_entry_title"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:singleLine="true"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:layout_toRightOf="@+id/flag2"
         />

4

2 に答える 2

1

RelativeLayout を使用しているため、layout_centerInParent 属性 (android:layout_centerInParent="true") を使用して "vs" TextView を中央に配置し、そのコンポーネントに対して他のコンポーネントを配置するだけで済みます。あなたのコードは次のようになります

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/list_item_entry_title"
        android:layout_toLeftOf="@+id/flag1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <ImageView
        android:id="@id/flag1"
        android:layout_toLeftOf="@+id/text"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        android:src="@drawable/bayern25" />

    <TextView
        android:id="@id/text"
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:layout_toRightOf="@+id/flag1"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:singleLine="true"
        android:text="-"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <ImageView
        android:id="@+id/flag2"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:layout_toRightOf="@id/text"
        android:src="@drawable/wolfsburg25" />

    <TextView
        android:id="@+id/list_item_entry_summary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@id/list_item_entry_title"
        android:layout_below="@id/list_item_entry_title"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:layout_toRightOf="@id/flag2"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceSmall" />
于 2012-09-18T19:19:43.447 に答える
0

次のように、LinearLayout の重みと重力を使用してこれを実現できます。

<LinearLayout
    android:width="match_parent"
    android:height="wrap_content"
    android:orientation="horizontal">
    <TextView
        android:width="0dp"
        android:weight="1"
        android:height="wrap_content"
        android:gravity="right"
        android:text="Team 1" />
    <TextView
        android:width="wrap_content"
        android:height="wrap_content"
        android:text="VS" />
    <TextView
        android:width="0dp"
        android:weight="1"
        android:height="wrap_content"
        android:gravity="left"
        android:text="Team 2" />
</LinearLayout>
于 2012-09-18T18:59:35.990 に答える