0

テキストビューと画像用の固定スペースがある下のレイアウトを実現したい。

「重み」プロパティを持たない相対レイアウトを使用しています。LinearLayout を使用して以下のレイアウトを実現するには?

ここに画像の説明を入力

以下は私のコードです

              <RelativeLayout>
                <TextView
            android:id="@+id/txt"
            android:paddingLeft="5dp"               
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"                 
            android:gravity="left" 
            android:textSize="14dp"     
            android:textColor="@android:color/white"/>        

              <TextView
                   android:id="@+id/date_n_time"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content" 
           android:padding="5dp"        
                   android:textColor="#E0FFFF"       
                   android:layout_below="@+id/txt"  />   

               <ImageView  android:id="@+id/imageview"
                   android:layout_height="wrap_content"
                   android:paddingRight="5dp"          
                   android:contentDescription="Image"
                   android:layout_width="wrap_content"          
                   android:layout_alignParentRight="true"
                   android:src="@drawable/icon"/>
      </RelativeLayout> 

上記の画像のように、テキストビューと画像を配置するために RelativeLayout を使用しました。しかし、textview と imageview は互いに重なっています。

4

4 に答える 4

0

次のように、TextView を画像の左側に簡単に配置できます。

android:layout_toLeftOf="@+id/yourimg"

マージンを追加すると、このレイアウトを簡単に実現できるはずです

于 2013-07-09T09:49:20.493 に答える
0

水平方向のlinearLayoutを使用し、内部にtextViewとimageViewを配置し、両方のlayout_widthを0dpに設定し、weightを必要な相対的な重みに設定する必要があります。たとえば、

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

<TextView 
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="4"
/>

<ImageView 
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"

/>
</LinearLayout>

textView の重みは 4 で、imageView の重みは 1 です。これは、textview がスペースの 4/5 を取得し、textView がスペースの 1/5 を取得することを意味します。試してみてください。

于 2013-07-09T09:45:27.980 に答える
0

と で使用LinearLayoutします。layout_weightSumlayout_weight

以下は、画面を縦に 2 分割する例です。

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

     <LinearLayout 
         android:layout_width="fill_parent"
         android:layout_height="0dp"
         android:layout_weight="0.9">

        <ListView
            android:id="@+id/frontpagetasklistid"
            android:layout_width="fill_parent"
            android:layout_height="375dp" >

        </ListView>
        </LinearLayout>
        <LinearLayout 
         android:layout_width="fill_parent"
         android:layout_height="0dp"
         android:layout_weight="0.1">

        <RelativeLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            >
        <EditText 
            android:id="@+id/edittextidAddTodayTask"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="@drawable/edittextselector"
            android:hint="Add Today Task"/>

        <ImageButton
            android:id="@+id/imagebuttonidAddTodayTask"
            android:layout_width="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:src="@drawable/addtask" />

        </RelativeLayout>
        </LinearLayout>

    </LinearLayout>
于 2013-07-09T09:35:51.110 に答える