我应该使用什么RelativeLayout属性?

发布于 2024-12-12 09:32:26 字数 4290 浏览 0 评论 0原文

我想为我的应用程序设计一个布局,如下图所示

layout to be design

但我遇到的问题是我申请相对布局的属性并不正确,如下面的我的 xml 代码所示,水平标尺图像具有 centerInParent 属性,垂直标尺图像也具有 centerInParent 属性,通过这样做,两个标尺都会到达准确的位置,但是当我放置一个子项时上面的水平标尺或子 toLeftOf 垂直标尺它们不会出现,因为 xml 文件的图形视图显示了以下原因:尽管通过应用 centerInParent,两个标尺都位于中心,但它们的引用仍保留在边缘,这就是为什么通过使用 layout_above 或 layout_toLeftOf 子标尺会超出布局

我的 xml 代码,

<?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>

所以请告诉我如何将这个主十字和图标实现到左、右、上、下,如图所示

i want to design a layout for my app as shown below in image

layout to be designed

but im getting problem which is that the properties im applying for relative layout are not going right as in below my xml code there is horizontal ruler image having centerInParent property and a verticle ruler image also having property of centerInParent by doing this the both rulers come to accurate place but when i put a child above the horizontal ruler or a child toLeftOf verticle ruler they dont appear as the graphical view of xml file shows the reason that although by applying centerInParent the both rulers come to center but their reference remains at edges thats why by using layout_above or layout_toLeftOf the childs go outside of layout

My xml 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>

so guys please tell me how can i achive this main cross and icon to lef,right and above,below it as shown in image

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等数载,海棠开 2024-12-19 09:32:26

试试这个..

<?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"
/>   

也许对你有帮助..

Try this..

<?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"
/>   

May be it helpful for you..

情何以堪。 2024-12-19 09:32:26

您可以使用嵌入在RelativeLayout 中的TableLayout。相对布局可用于将 TableLayout 在屏幕上居中,在 TableLayout 中,您可以添加图片/按钮并说明您希望 TableLayout 有多少行和列。

You could use a TableLayout embedded in a RelativeLayout. The RelativeLayout can be used to center the TableLayout on the screen and in the TableLayout you can add your pictures/buttons and state how many rows and colums you want the TableLayout to have.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文