android floating layout

1.

gravity: floats internal elements.

A view (TextView,ImageView,ImageButton...) is a div, but it can't have flow: left|right and other attributes like a Div. if you don't want to use floating positioning, you can add a third-party dependency. The usage is as follows:

//Add dependency in build
compile 'com.nex3z:flow-layout:1.0.0'

xml Middle layout:
<com.nex3z.flowlayout.FlowLayout
    android:id="@+id/flow"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:flChildSpacing="7dp"
    app:flRowSpacing="8dp" />

//Properties are:
FlowLayout.LEFT                -Align left

FlowLayout.RIGHT             -Align right

FlowLayout.CENTER—–Align Center

FlowLayout.LEADING -Align with start side

FlowLayout.TRAILING--Align with end side


 



However, in android layout, the commonly used methods of centering, right and left are as follows:

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:background="#242424">

        <TextView
            android:onClick="closedAc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:text="Close" />


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.8"
            android:gravity="center"
            android:paddingLeft="-100dp"
            android:text="Industrial University Test" />


    </LinearLayout>

 

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:gravity="center_vertical"
        android:background="#242424"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Close"
            android:gravity="right"
            android:layout_weight="0.3"
            android:textColor="#ffffff"
            android:onClick="closedAc"
            android:id="@+id/button2"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="radio reception"
            android:gravity="center"
            android:layout_weight="0.3"
            android:textColor="#ffffff"
            android:onClick="closedB"
            />
        <TextView
            android:layout_width="wrap_content"

            android:layout_height="wrap_content"
            android:text="speech"
            android:gravity="left"
            android:layout_weight="0.3"
            android:textColor="#ffffff"
            android:onClick="closedC"
            />
    </LinearLayout>

 

When the arrangement of LineaLayout is horizontal, the layout  gravity only takes effect in the vertical direction, because the length in the horizontal direction is not fixed at this time. The length in the horizontal direction will change with each control added, so the alignment in this direction cannot be specified. In the same way, when the arrangement of LineaLayout is vertical, the arrangement of layout gravity only takes effect in the horizontal direction.

Summary:

Code in < LinearLayout >
        android:orientation="horizontal"
        android:gravity="center_vertical"

Code in < xxxview >

            android:gravity="right"
            android:layout_weight="0.3"

Mainly the above lines of code realize the layout

 

2. Android: layout'weight represents a value of "importance", and the size of the value represents how much space the control can occupy in the screen. The larger the value, the more "free" space the control can occupy in the parent control. The default weight is 0. Minimum weight is 0, maximum is 1


 

Keywords: Android xml

Added by starnol on Fri, 20 Dec 2019 18:11:26 +0200