簡體   English   中英

LinearLayout彼此相鄰

[英]LinearLayout's next to each other

我試圖使兩個LinearLayout彼此相鄰,但是下面的代碼無法正常工作,它把它們放在頂部。

你能幫忙嗎? 還是您有更好的主意?

謝謝?

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

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" 
    android:layout_weight="0.5"
    android:background="#999"> 



</LinearLayout>

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" 
android:layout_weight="0.5"
    android:background="#977000"> 



</LinearLayout>



</LinearLayout>

用這個只要改變android:orientation="horizontal"代替android:orientation="vertical

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:background="#999"
    android:orientation="horizontal" >
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:background="#977000"
    android:orientation="horizontal" >
</LinearLayout>

在頂部LinearLayoutandroid:orientation="vertical"替換為android:orientation="horizontal"

將外部線性布局的方向設置為“水平”。

嘗試將您的第一個linearLayout設置為“水平”,而不是“垂直”

這個

android:orientation="vertical" >

必須

android:orientation="horizontal" >

在您的外部LinearLayout中

android:orientation="horizontal"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout 
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal" 
android:layout_weight="1"
android:background="#999"> 
</LinearLayout>
<LinearLayout 
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal" 
android:layout_weight="1"
android:background="#977000"> 
</LinearLayout>
</LinearLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM