2011-12-26 7 views
0

Я пытаюсь создать макет, но я не слишком уверен, как точно описать, что я хочу делать. Поэтому я создал изображение ниже, чтобы описать, что я пытаюсь.Элементы управления Android рядом друг с другом?

enter image description here

Я теряюсь, как получить вертушку и EditText рядом с ImageView, как у меня на картинке.

Вот мой XML до сих пор.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <Button android:id="@+id/btnCancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:text="Cancel" 
      /> 
     <Button android:id="@+id/btnAdd" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:text="Add" 
      /> 
    </RelativeLayout> 
    <RelativeLayout> 
     <ImageView 
      android:id="@+id/imgExercise" 
      android:layout_width="50px" 
      android:layout_height="50px" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      /> 
     <Spinner 
      android:id="@+id/spCategory" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      /> 
     <EditText 
      android:id="@+id/etName" 
      android:hint="Name" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      /> 
    </RelativeLayout> 
    <EditText 
     android:id="@+id/etDescription" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:lines="5" 
     android:gravity="top" 
     android:hint="Description" 
     /> 
</RelativeLayout> 

ответ

9

Советы -1:

Прежде всего, вам не нужно принимать суб RelativeLayout, потому что вы можете подготовить тот же макет только в одном родительском RelativeLayout. Я возвращаюсь с точным ответом.

советы - 2:

«ПВ» не является предпочтительным, чтобы определить измерения, вместо этого вы можете использовать купанием или дп (плотность независимого пикселя) (по высоте/ширине зрения) и зр (масштабированный пиксель) для шрифта.

Решение:

<?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="fill_parent" 
android:padding="5dp"> 

     <Button android:id="@+id/btnCancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:text="Cancel" 
      /> 
     <Button android:id="@+id/btnAdd" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:text="Add" 
      /> 

     <ImageView 
      android:id="@+id/imgExercise" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/btnCancel" 
      android:src="@drawable/icon" 
      android:scaleType="fitXY" 
      /> 

     <Spinner 
      android:id="@+id/spCategory" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/imgExercise" 
      android:layout_below="@+id/btnCancel" 
      android:layout_alignTop="@+id/imgExercise" 
      /> 

     <EditText 
      android:id="@+id/etName" 
      android:hint="Name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/imgExercise" 
      android:layout_below="@+id/spCategory" 
      android:layout_alignBottom="@+id/imgExercise" 
      /> 


    <EditText 
     android:id="@+id/etDescription" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:lines="5" 
     android:gravity="top" 
     android:hint="Description" 
     android:layout_below="@+id/imgExercise" 
     /> 
</RelativeLayout> 

Выход:

enter image description here

+0

Здравствуй Paresh сэр Ji .. – Lucifer

+0

@Lucifer да дорогой .. Роджер :) –

+0

приходит в Каузальный чат. – Lucifer

1

Попробуйте использовать

android:layout_toRightOf="@+id/imgExercise" 

в обоих Spinner и EditText теге

, а также использовать

android:layout_alignParentBottom="true" 

внутри EditText тег InstEd из

android:layout_alignParentTop="true" 
0

положить прядильщик и edittext в одну линейную компоновку, а ее ориентация - вертикальная. этот макет установить свойство android:layout_alignParentRight="true"

0

@lanks, если вы не собираетесь ничего перекрываться то LinearLayout это путь. Я бы рекомендовал soemthing как это (это Суда коды, убедитесь, что используется правильный синтаксис в вашем XML)

<LinearLayout 
    android:orientation="vertical" 
> 
<LinearLayout 
android:orientation="horizontal" 
> 
<BUtton 1/> 
<Button 2/> 
</LinearLayout> 
<LinearLayout 
android:orientation="horizontal" 
> 
<ImageView /> 

<LinearLayout 
android:orientation="vertical" 
> 
<spinner /> 
<TextField /> 
... 
1
<?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="fill_parent" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/btnCancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:text="Cancel" /> 

     <Button 
      android:id="@+id/btnAdd" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:text="Add" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/imgExercise" 
      android:layout_width="50px" 
      android:layout_height="50px" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" /> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_toRightOf="@+id/imgExercise" > 

      <Spinner 
       android:id="@+id/spCategory" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:entries="@string/app_name" /> 

      <EditText 
       android:id="@+id/etName" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:hint="Name" /> 
     </LinearLayout> 
    </RelativeLayout> 

    <EditText 
     android:id="@+id/etDescription" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:hint="Description" 
     android:lines="5" /> 

</LinearLayout> 
Смежные вопросы