質問

私は次のような外観にリストビューの行を取得しようとしている。

| Text-Text-Text                        <ImageButton> |
右端にスナップIMAGEBUTTONで

。これどうやってするの?ここで私が使用している現在のレイアウトコードです。何が間違っているのでしょうか?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/layercontainer"
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:background="#699">
 <LinearLayout
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:layout_gravity="left">
   <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="YO HOW SI IT GOESSDA" />
 </LinearLayout>

 <LinearLayout
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:layout_gravity="right">
   <ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/trash" />
 </LinearLayout>
</LinearLayout>
私のコードは、現在、この生成します。 grrrが

役に立ちましたか?

解決

ステップ#1:使用RelativeLayoutベース

ステップ#2:ImageButtonを持つものとして、あなたのandroid:layout_alignParentRight="true"を入れて

ステップ#3:TextViewは、垂直配向のために、おそらくいくつかの他のandroid:layout_alignParentLeft="true"値(android:layout_toLeftOf="..."あなた...のIDである)ImageButtonRelativeLayout.LayoutParamsを備えた置き

他のヒント

次のコードは、いくつかのテキスト(水平左揃え、android:layout_alignParentLeft="true"を介して)、アイコン(水平android:layout_alignParentRight="true"介し右揃え)、およびすべての垂直中心(android:layout_centerVertical="true")を有するリストビューの列を作成する方法の例を提供ます。

(グローバルスタイルに応じYMMV、)次のようにレンダリング

コード例のレンダリング

一番右にあるアイコンの左に配置することができますコメントアウトされた追加のアイコンもあります。有効にするためにXMLコメントタグを削除します。

ここではレイアウトXMLは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:descendantFocusability="blocksDescendants"
    android:padding="6dp">
    <!-- Note: android:descendantFocusability="blocksDescendants" set to ensure that
     OnItemClickListener works by ensuring constituent controls do not take focus -->


    <TextView
        android:id="@+id/lbl_list_item_row_text"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:lines="1"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:text="My List Item Text"
        />

    <!-- This can be uncommented to add another button 

    <ImageButton
        android:id="@+id/btn_additional_icon"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/icon_additional_icon"
        android:layout_centerVertical="true"
        android:layout_width="wrap_content"
        android:padding="3dp"
        android:background="@null" 
        android:src="@drawable/icon_additional_icon" />

    -->

    <ImageButton
        android:id="@+id/icon_additional_icon"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:background="@null"
        android:padding="3dp"
        android:src="@drawable/icon_right_aligned_icon" />
</RelativeLayout>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top