简体   繁体   中英

How to set up the layout of the alignment?

I don't know how to set up the layout of the alignment? Maybe this is a simple question but i am no idea,And I'm a new Android developer.Please provide the way of thinking,Thank you! This is my page to display hierarchical relationship.

This page is made up of two layout, parent and child:

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/table_cell_bg_color">
        <TextView
            android:id="@+id/parent_task_list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:paddingLeft="40px"
            android:paddingTop="6px"
            android:paddingBottom="6px"
            android:textSize="18sp"
            android:textColor="#2B2B2B"
            android:text="No data"/>

        <ImageView
            android:id="@+id/arrow_parent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:src="@drawable/ram_arrow_close"/>


    </LinearLayout>

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

    <TextView
        android:id="@+id/child_task_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.4"
        android:paddingLeft="60px"
        android:paddingTop="10px"
        android:paddingBottom="10px"
        android:textSize="18sp"
        android:textColor="#2B2B2B"
        android:text="No Data" />

    <TextView
        android:id="@+id/child_task_count"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.3"
        android:paddingLeft="60px"
        android:paddingTop="10px"
        android:paddingBottom="10px"
        android:textSize="18sp"
        android:textStyle="bold"
        android:textColor="@color/text_blue"
        android:text="No Data"/>

    <ImageView
        android:id="@+id/arrow_child"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_weight="0.3"
        android:src="@drawable/ram_arrow_icon"/>

</LinearLayout>

Possible solutions for you.

  1. Table Layout

  2. Relative Layout

You can use with layout

android:gravity=""

and

android:layout_gravity=""

Use this Code

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/table_cell_bg_color">
<TextView
    android:id="@+id/child_task_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#2B2B2B"
    android:text="No Data" />
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/arrow_layout"
    android:layout_toLeftOf="@+id/arrow_layout"
    android:layout_toStartOf="@+id/arrow_layout"
    android:paddingRight="10dp">
    <TextView
        android:id="@+id/child_task_count"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textColor="@color/text_blue"
        android:text="No Data"/>
</LinearLayout>

<LinearLayout
    android:id="@+id/arrow_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:paddingRight="10dp">
    <ImageView
        android:id="@+id/arrow_child"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ram_arrow_icon"/>

</LinearLayout>

I thing you are using list view or recyclerview so you should use this view to repeat the content based on array size

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM