какие свойства RelativeLayout я должен использовать? - PullRequest
1 голос
/ 28 октября 2011

Я хочу создать макет для моего приложения, как показано ниже на изображении

layout to be designed

, но я получаю проблему, заключающуюся в том, что свойства, которые я применяю для относительного макета, работают неправильнокак показано ниже в моем XML-коде, есть горизонтальное изображение линейки, имеющее свойство centerInParent, и изображение линейной линейки, также имеющее свойство centerInParent. При этом обе линейки оказываются в точном месте, но когда я помещаю дочерний элемент выше горизонтальной линейки или дочерний элемент линейки toLeftOfони не отображаются, поскольку графическое представление файла XML показывает причину, по которой при применении centerInParent обе линейки приходят в центр, но их ссылки остаются по краям, поэтому при использовании layout_above или layout_toLeftOf дочерние элементы выходят за пределы макета

Myxml code

<?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:background="#FFFFFF"
          android:orientation="vertical">

       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="@drawable/title"
        >

       <ImageView
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"
          android:id="@+id/icon_img"
          android:layout_alignParentLeft="true"
          android:layout_marginLeft="10dip"
          android:layout_marginTop="2.5dip"
          android:src="@drawable/smicon"
       />
       <TextView  
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="15dip"
          android:layout_toRightOf="@id/icon_img"
          android:layout_marginTop="3dip"
          android:text="Welcome To JEM"
          android:textStyle="bold"
          android:id="@+id/wcm_id"
          android:textSize="18dip"
          android:textColor="#FFFFFF"
       />

      <TextView  
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"
          android:layout_alignBottom="@id/wcm_id"
          android:layout_alignParentRight="true"
          android:layout_marginRight="5dip"
          android:text="APPS BY SAM"
          android:id="@+id/app_by"
          android:textSize="16dip"
          android:textColor="#FFFFFF"
      />
     </RelativeLayout>

    <!-- This relative layout which is showing the main cross and icon around it -->
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="20dip"
     >


    <ImageView
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"
          android:id="@+id/center_hr"
          android:layout_centerInParent="true"
          android:src="@drawable/horizontal"
    />

   <ImageView
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"
          android:id="@+id/center_vr"
          android:layout_centerInParent="true"
          android:src="@drawable/verticle"
   />

  <ImageView
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"
          android:layout_above="@id/center_hr"
          android:layout_toLeftOf="@id/center_vr"
          android:id="@+id/getuser"
          android:src="@drawable/adduser"
  />

 <ImageView
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content"
           android:layout_above="@id/center_hr"
           android:layout_toRightOf="@id/center_vr"
           android:id="@+id/set"
           android:src="@drawable/set"
 />

 <ImageView
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content"
           android:layout_below="@id/center_hr"
           android:layout_toLeftOf="@id/center_vr"
           android:id="@+id/get"
           android:src="@drawable/get"
 />

 <ImageView
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content"
           android:layout_below="@id/center_hr"
           android:layout_toRightOf="@id/center_vr"
           android:id="@+id/ico"
           android:src="@drawable/icon"
 />

</RelativeLayout>

</LinearLayout>

поэтому, ребята, скажите, пожалуйста, как мне получить этот основной крест и значок слева, справа и сверху под ним, как показано на рисунке

Ответы [ 2 ]

1 голос
/ 28 октября 2011

Попробуйте это ..

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView 
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
 <ImageView 
android:id="@+id/vertical_ruler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/imageView1"/>

<ImageView 
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/vertical_ruler"
/>
 <ImageView 
android:id="@+id/horizontal_ruler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/imageView1"/>
<ImageView 
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/horizontal_ruler"/>
 <ImageView 
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/vertical_ruler"
android:layout_below="@id/horizontal_ruler"
/>   

Может быть, это полезно для вас ..

0 голосов
/ 28 октября 2011

Вы можете использовать TableLayout, встроенный в RelativeLayout.RelativeLayout можно использовать для центрирования TableLayout на экране, а в TableLayout вы можете добавить свои изображения / кнопки и указать, сколько строк и столбцов вы хотите иметь в TableLayout.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...