0

私はAndroidにかなり慣れていません。右下隅のリストビュー項目テンプレートに 2 つのボタンを追加したいと考えています。

今、私はそのようなレイアウトを持っています: 既存のレイアウト

そしてコード:

<ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="6dip"
    android:src="@drawable/ic_launcher" />

<TextView
    android:id="@+id/secondLine"
    android:layout_width="fill_parent"
    android:layout_height="26dip"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@id/icon"
    android:ellipsize="marquee"
    android:singleLine="true"
    android:text="Details"
    android:textSize="12sp" />

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/secondLine"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_alignWithParentIfMissing="true"
    android:layout_toRightOf="@id/icon"
    android:gravity="center_vertical"
    android:text="Test title"
    android:textSize="16sp" />

私が達成したいのは、右下隅に次のような2つのボタンを追加することです:

期待される

RelativeLayoutまた、ボタンを水平に配置してLinearLayoutもう1つ子を追加しようとしましLinearLayoutたが、リストビューのアイテム行にはまったく表示されません。

4

5 に答える 5

0

目的のレイアウトには、以下のコードを使用してください。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#DADADA" >

    <RelativeLayout
        android:id="@+id/ItemMainContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:padding="5dp" >

        <ImageView
            android:id="@+id/Icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/image" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@id/Icon"
            android:orientation="vertical" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Test title" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Details" />
        </LinearLayout>
    </RelativeLayout>

    <View
        android:id="@+id/HorizontalSeparator"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@id/ItemMainContainer"
        android:layout_margin="5dp"
        android:background="#CCCCCC" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/HorizontalSeparator"
        android:layout_margin="2dp" >

        <TextView
            android:id="@+id/Button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_margin="5dp"
            android:clickable="true"
            android:drawableLeft="@drawable/delete"
            android:gravity="center"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:text="Button2" />

        <View
            android:id="@+id/Separator"
            android:layout_width="1dp"
            android:layout_height="27dp"
            android:layout_toLeftOf="@id/Button2"
            android:background="#CCCCCC" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_toLeftOf="@id/Separator"
            android:clickable="true"
            android:drawableLeft="@drawable/delete"
            android:gravity="center"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:text="Button1" />
    </RelativeLayout>

</RelativeLayout>

結果のスクリーンショットも添付しました。スクリーンショット

それに応じてアセットを変更します。

于 2013-08-30T09:05:16.870 に答える
0

あなたのことをよく理解していれば、各リスト項目の右下にあるボタンが必要です。もしそうなら、以下はあなたのために働くでしょう:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/MainLayout"
android:layout_width="fill_parent"
android:layout_height= "fill_parent">
   <RelativeLayout
         android:id="@+id/FirstLayout"
         android:layout_width="fill_parent"
         android:layout_height= "fill_parent">
           <ImageView
               android:id="@+id/icon"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:layout_alignParentBottom="true"
               android:layout_alignParentTop="true"
               android:layout_marginRight="6dip"
               android:src="@drawable/ic_launcher" />

           <TextView
               android:id="@+id/secondLine"
               android:layout_width="fill_parent"
               android:layout_height="26dip"
               android:layout_alignParentBottom="true"
               android:layout_alignParentRight="true"
              android:layout_toRightOf="@id/icon"
               android:ellipsize="marquee"
               android:singleLine="true"
               android:text="Details"
               android:textSize="12sp" />

           <TextView
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:layout_above="@id/secondLine"
               android:layout_alignParentRight="true"
               android:layout_alignParentTop="true"
               android:layout_alignWithParentIfMissing="true"
               android:layout_toRightOf="@id/icon"
               android:gravity="center_vertical"
               android:text="Test title"
               android:textSize="16sp" />
     </RelativeLayout>
     <RelativeLayout
         android:id="@+id/SecondLayout"
         android:layout_below="@+id/FirstLayout"
         android:layout_width="fill_parent"
         android:layout_height= "fill_parent">
              <Button 
                  android:id="@+id/btnTwo"
                  android:text ="Button Two"
                  android:layout_alignParentRight="true"/>
              <Button 
                  android:id="@+id/btnOne"
                  android:text ="Button One"
                  android:layout_toLeftOf="@+id/btnTwo"/>
      </RelativeLayout>
</RelativeLayout>

幸運を!

于 2013-08-30T08:20:48.583 に答える
0

私が間違っていなければ、あなたはコンポーネントのアライメント調整を探しています。android:layout_alignParentXXXXlayout_above/below属性を既に使用しています。いくつかの変更を行ってください。目的のものが得られます。

以下のコードを確認しましたが、これが役立つ場合があります。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/rel2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/lin1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" >
// here place you existing code
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/lin1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true" >

        <Button
            android:id="@+id/button1"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:id="@+id/button2"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    </LinearLayout>

</RelativeLayout>
于 2013-08-30T09:34:42.573 に答える