11
votes

CSS "Float:" Propriété équivalente à droite à Linearlayout sur Android?

sur CSS, nous pouvons écrire:

<LinearLayout android:id="@+id/linearLayout1" android:layout_gravity="right" android:gravity="right"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_weight="1" android:weightSum="2" android:orientation="horizontal">
        <!-- First Column should be on the right : Text1-->
        <LinearLayout android:id="@+id/linearLayout2"
            android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="right" android:gravity="right"
            android:layout_weight="1">...</LinearLayout>
        <!-- Second Column should be on the left : Text2 -->
        <LinearLayout android:id="@+id/linearLayout3"
            android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="right" android:gravity="right"
            android:layout_weight="1">...</LinearLayout>
</LinearLayout>


2 commentaires

Est-ce qu'il semble de haut en bas?


@Las_vegas MMM, la mise en page en général ne fonctionne pas, je vais donc essayer de simuler le flotteur: à droite en utilisant linearlayout? Merci .


4 Réponses :


0
votes

Ceci peut être

<LinearLayout android:id="@+id/linearLayout1"
    android:gravity="right"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:weightSum="2"
    android:orientation="horizontal"
    android:layout_gravity="right"
    >
    <!-- Second Column should be on the left : Text2 -->
    <LinearLayout android:id="@+id/linearLayout3"
        android:layout_width="wrap_content" android:layout_height="fill_parent" 
        android:layout_weight="1">...</LinearLayout>
    <!-- First Column should be on the right : Text1-->
    <LinearLayout android:id="@+id/linearLayout2"
        android:layout_width="wrap_content" android:layout_height="fill_parent"
        android:layout_weight="1">...</LinearLayout>


3 commentaires

Je pense que vous venez d'échanger du texte2 avec text1 physiquement? Je peux faire ça, mais je ne veux pas? Dans CSS, nous pouvons laisser l'élément flotter à droite même s'il est écrit en premier!


J'ai aussi mis une gravité sur le parent


Vous avez layout_gravity = "Droite" répété deux fois dans le XML du parent



-6
votes

Il suffit de définir l'orientation linéarlayout sur horizontal xxx


0 commentaires

0
votes

Je ne sais pas si cela est possible avec linearlayout em> strong>, mais vous pouvez réaliser ce dont vous avez besoin avec une relativenelle forte> comme ceci:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <LinearLayout
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="Text1"
            android:textAppearance="@android:style/TextAppearance.Large" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_toLeftOf="@+id/text1"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="Text1"
            android:textAppearance="@android:style/TextAppearance.Large" />
    </LinearLayout>

</RelativeLayout>


2 commentaires

Comment puis-je faire une pause de ligne? Je veux que beaucoup de boutons se comportent comme la propriété CSS-Float :)


@Stefanbrendle Vous pouvez utiliser cette structure à l'intérieur d'une linerlayout horizontale. ··· ···



0
votes

Il suffit d'ajouter: xxx

gravity = "droite" est pour le texte à flotter droit, comme l'alignement de texte.


0 commentaires