0

XML ファイルに次のコードがあります。

        <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="60dip"
        android:layout_marginLeft="13dp"
        android:layout_marginRight="13dp"
        android:layout_marginTop="20dp"
        android:background="@color/white"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/name_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/pic"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_marginLeft="6dp" />

            <EditText 
                android:id="@+id/name"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_alignRight="@id/pic" />          
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/phone_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/phone_pic"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_marginLeft="6dp"
                android:layout_weight="0.15" />

            <EditText 
                android:id="@+id/phone_number"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_alignRight="@id/phone_pic" />            
        </RelativeLayout>

    </LinearLayout> 

の内側にImageViewandフィールド、 の右側にEフィールドが必要です。しかし、グラフィカルなレイアウトを確認すると、とが の外側に配置されています。私は何が間違っていて、これを修正する方法は?EditTextRelativeLayoutEditTextImageViewEditTextImageViewRelativeLayoutLinearLayout

4

6 に答える 6

3

RelativeLayout水平に置き換えてみませんかLinearLayout

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="60dip"
    android:layout_marginLeft="13dp"
    android:layout_marginRight="13dp"
    android:layout_marginTop="20dp"
    android:background="@color/white"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/name_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/pic"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginLeft="6dp" />

        <EditText 
            android:id="@+id/name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp" />          
    </LinearLayout>

    <LinearLayout
        android:id="@+id/phone_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/phone_pic"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginLeft="6dp"
            android:layout_weight="0.15" />

        <EditText 
            android:id="@+id/phone_number"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp" />            
    </LinearLayout>

</LinearLayout> 
于 2012-10-22T11:47:57.367 に答える
1

これはあなたを助けるでしょう........

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_launcher" />


    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
         android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/imageView1"
        android:ems="10" >

        <requestFocus />
    </EditText>

</RelativeLayout>

ここに画像の説明を入力

于 2012-10-22T11:56:00.983 に答える
0

属性を使用してみてくださいandroid:layout_toRightOf

このビューの左端を、指定されたアンカービューIDの右側に配置します。このビューの左マージンとアンカービューの右マージンに対応します。

だからこれを試してみてください:

    <RelativeLayout
        android:id="@+id/name_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/pic"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginLeft="6dp" />

        <EditText 
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_toRightOf="@+id/pic" />          
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/phone_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/phone_pic"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginLeft="6dp"
            android:layout_weight="0.15" />

        <EditText 
            android:id="@+id/phone_number"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_toRightOf="@+id/phone_pic" />            
    </RelativeLayout>

</LinearLayout> 

例をよりよく理解したい場合は、ここに1つあります。そして、あなたがテストできるように、まだソースコードがあります。http://www.mkyong.com/android/android-relativelayout-example/

于 2012-10-22T11:52:59.483 に答える
0

このコードを試すことができます

<?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="60dp"
android:layout_marginLeft="13dp"
android:layout_marginRight="13dp"
android:layout_marginTop="20dp"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/name_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/pic"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:src="@drawable/ic_launcher" />

    <EditText
        android:id="@+id/name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_toRightOf="@id/pic" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/phone_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/phone_pic"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:src="@drawable/ic_launcher" />

    <EditText
        android:id="@+id/phone_number"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_toRightOf="@id/phone_pic" />

</RelativeLayout>

于 2012-10-22T11:59:06.823 に答える
0

rogcg氏が言ったように、android:layout_toRightOfを試してみてください。ただし、Linear Layout 属性にも特定の変更を加える必要があります。android:layout_height="60dip" を指定しました

これにより、連続した相対レイアウトが非表示になります。親を埋めるようにして、layout_toRightOfを設定します。それが動作します。

また、画像ビューの場合、次のように src を割り当てます android:src="@drawable/someimage"

よろしくお願いします、 Rajamanickem.S

于 2012-10-22T12:01:10.623 に答える
-1

レイアウトのこれらのコード行を変更してください。これは間違っています

android:layout_alignRight="@id/phone_pic" 
android:layout_alignRight="@id/pic" 

これらの下の行を書く

android:layout_alignRight="@+id/phone_pic"
  android:layout_alignRight="@+id/pic" 
于 2012-10-22T11:45:29.623 に答える