0

listViewがあり、list_itemの左側にImageButton、中央にTextView、右側にImageButtonがあります。

<?xml version="1.0" encoding="utf-8"?>    
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:gravity="center">
      <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center">
        <ImageButton android:id="@+id/parkingState" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
           android:layout_marginTop="4dip" 
           android:layout_marginRight="4dip"
           android:layout_marginLeft="4dip"
           android:layout_gravity="center"
           android:background="@null"/>
        <LinearLayout 
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content" 
            android:orientation="vertical"
            android:gravity="center"> 
            <TextView android:id="@+id/LblSubTitle"
                android:gravity="center_horizontal"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textStyle="normal"
                android:textColor="#444444"
                android:textSize="12sp" /> 
        </LinearLayout>
        <ImageButton android:id="@+id/parking_details" 
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:gravity="center"
              android:layout_marginRight="4dip"
              android:layout_marginLeft="4dip"
              android:layout_marginTop="4dip"
              android:layout_marginBottom="4dip"
              android:background="@null"/>
      </LinearLayout>
</LinearLayout>

結果は次のとおりです。

ここに画像の説明を入力してください

でも、左と右の画像が欲しいです。どうすればこの効果を得ることができますか?

4

7 に答える 7

1

RelativeLayoutを使用して使用-

 <ImageButton android:id="@+id/parkingState" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="4dip" 
    android:layout_marginRight="4dip"
    android:layout_marginLeft="4dip"
    android:layout_gravity="center"
    android:background="@null"
    android:layout_alignParentLeft="true"/>

同様に、他の画像ボタンについてもalignParentRight=trueです。

于 2013-01-31T09:58:19.650 に答える
1

次のように、最初のlinearlayoutに「fill_parent」と記述します。

<?xml version="1.0" encoding="utf-8"?>    
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
于 2013-01-31T09:59:02.093 に答える
1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/parkingState"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_gravity="center"
        android:layout_marginLeft="4dip"
        android:layout_marginRight="4dip"
        android:layout_marginTop="4dip"
        android:background="@null"
        android:contentDescription="@string/app_name"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/LblSubTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@+id/parking_details"
        android:layout_toRightOf="@+id/parkingState"
        android:gravity="center_vertical"
        android:singleLine="false"
        android:text="write something here to display in the text"
        android:textColor="#444444"
        android:textSize="12sp"
        android:textStyle="normal" />

    <ImageButton
        android:id="@+id/parking_details"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="4dip"
        android:layout_marginLeft="4dip"
        android:layout_marginRight="4dip"
        android:layout_marginTop="4dip"
        android:background="@null"
        android:contentDescription="@string/app_name"
        android:gravity="center"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

あなたが友達にしたい上記のコードを試してみてください

于 2013-01-31T09:59:17.100 に答える
1

RelativeLayoutの代わりに使用すると、タグLinearLayoutを使用できます。layout

android:layout_alignParentLeft = "true"android:layout_alignParentRight = "true"

TextView使用を集中させるために:android:layout_centerHorizontal="true"

<RelativeLayout bla bla 
 bla bla >
<ImageView bla bla 
   bla bla 
   android:layout_alignParentLeft="true" />

<TextView bla bla 
   bla bla 
   android:layout_centerHorizontal="true" />

<ImageView bla bla 
   bla bla 
   android:layout_alignParentRight="true" />
</RelativeLayout>
于 2013-01-31T09:59:19.040 に答える
1

これをImageButtunタグに入れます:

android:layout_alignParentLeft="true"

android:layout_alignParentRight="true"
于 2013-01-31T10:07:30.083 に答える
0

親LinerLayoutには。がありandroid:layout_width="wrap_content"ます。に変更しfill_parentます。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical" >
    ....
    ....
    ....

</LinearLayout>
于 2013-01-31T10:00:59.360 に答える
0

以下に示すように線形レイアウトを追加します...

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
    <ImageButton android:id="@+id/parkingState" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dip" 
        android:layout_marginRight="4dip"
        android:layout_marginLeft="4dip"
        android:layout_gravity="center"
        android:background="@drawable/ic_launcher"/>


    <LinearLayout 
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content" 
        android:orientation="vertical"
        android:gravity="center"
        > 
        <TextView android:id="@+id/LblSubTitle"
            android:gravity="center_horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textStyle="normal"
            android:text="hhhh"
            android:textColor="#444444"
            android:textSize="12sp" /> 

    </LinearLayout>

    <ImageButton android:id="@+id/parking_details" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_marginRight="4dip"
        android:layout_marginLeft="4dip"
        android:layout_marginTop="4dip"
        android:layout_marginBottom="4dip"
        android:background="@drawable/ic_launcher"/>
</LinearLayout>

</LinearLayout>
于 2013-01-31T10:01:12.490 に答える