2013-03-25 97 views
2

嗨即時嘗試設計我的應用程序的Android手機和平板電腦。所以我已經設計了它,但需要重新設計以適應不同屏幕的縮放目的。在同一屏幕上的兩個線性佈局

enter image description here

這是佈局我去了。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LinearLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="@color/white"> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:weightSum="2" 
     android:orientation="horizontal" > 

    <fragment 
     android:id="@+id/map" 
     android:layout_marginTop="5dp" 
     android:layout_weight=".1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     class="com.google.android.gms.maps.MapFragment" 
     /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_weight=".25" 
     android:layout_marginLeft="34dp" 
     android:layout_marginTop="10dp" 
      android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="ClickTourismButton" 
     android:text="@string/Tourism" /> 

    <Button 
     android:id="@+id/button4" 
     android:layout_weight=".25" 
      android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="34dp" 
     android:text="@string/Nearby" /> 
    <Button 
     android:id="@+id/button2" 
     android:layout_weight=".25" 
     android:layout_marginLeft="34dp" 
      android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/Favourites" /> 
    <Button 
     android:id="@+id/button1" 
     android:layout_weight=".25" 
      android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="34dp" 
     android:text="@string/Map" /> 

    </LinearLayout> 


    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="2" 
     android:orientation="horizontal" > 
    <TextView 

     android:layout_marginLeft="10dp" 
     android:layout_marginTop="5dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textIsSelectable="true"  
     android:id="@+id/feedupdate1" /> 

    <ListView 
     android:id="@android:id/list" 
     android:background="@color/red" 
     android:layout_weight="1"  
     android:layout_marginTop="5dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp"/> 

    <TextView 
     android:id="@+id/empty" 
     android:textIsSelectable="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="5dp"/> 
    <TextView 
     android:id="@+id/feedupdate"   
     android:layout_marginLeft="6dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="430dp" 
     android:textIsSelectable="true"/> 
    <ListView 

     android:id="@+id/list1" 
     android:background="@color/blue" 
     android:layout_weight="1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="430dp" 
     android:layout_marginLeft="6dp" /> 

    </LinearLayout> 
</RelativeLayout> 

當我運行應用程序時,兩個線性佈局是在彼此之上?或者上面看到的地圖片段作爲黑色矩形佔據了所有的屏幕?我不知道我做錯了什麼,我查看了幾個教程,看起來正確嗎?

需要幫助,請

感謝


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LinearLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:weightSum="2" 
    android:background="@color/white"> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

    <fragment 
     android:id="@+id/map" 
     android:layout_marginTop="5dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     class="com.google.android.gms.maps.MapFragment" 
     /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_marginLeft="34dp" 
     android:layout_marginTop="10dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="ClickTourismButton" 
     android:text="@string/Tourism" /> 

    <Button 
     android:id="@+id/button4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="34dp" 
     android:text="@string/Nearby" /> 
    <Button 
     android:id="@+id/button2" 
     android:layout_marginLeft="34dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/Favourites" /> 
    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_marginLeft="34dp" 
     android:text="@string/Map" /> 

    </LinearLayout> 


    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" > 
    <TextView 

     android:layout_marginLeft="10dp" 
     android:layout_marginTop="5dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textIsSelectable="true"  
     android:id="@+id/feedupdate1" /> 

    <ListView 
     android:id="@android:id/list" 
     android:background="@color/red"  
     android:layout_marginTop="5dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp"/> 

    <TextView 
     android:id="@+id/empty" 
     android:textIsSelectable="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="5dp"/> 
    <TextView 
     android:id="@+id/feedupdate"   
     android:layout_marginLeft="6dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="430dp" 
     android:textIsSelectable="true"/> 
    <ListView 

     android:id="@+id/list1" 
     android:background="@color/blue" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="430dp" 
     android:layout_marginLeft="6dp" /> 

    </LinearLayout> 
</LinearLayout> 

enter image description here

一個組件佔用每邊? 其分成兩部分,但地圖片段佔用所有的一面,第一個列表視圖佔據了所有其他的???

+0

使兩個線性佈局的android:weight =「1」。這將在他們之間平分屏幕。 – 2013-03-25 12:55:31

+0

它現在分成兩部分,但一部分佔據了每一邊的所有空間?我如何給每個組件空間? – PropK 2013-03-25 13:17:51

回答

8
  1. 更改您要VERTICAL

  2. 兩個孩子LinearLayouts的方向對於頂部除去相對和使用的LinearLayout與方向HORIZONTAL 並有weightSum=2

  3. 現在兩個孩子的LinearLayout意見給予layout_width="0dp"layout_weight="1"


示例XML爲您提供:http://pastebin.com/2MCBN9qk

+0

是所有我應該改變@MKJPrarekh,因爲它現在分爲兩個,但地圖片段佔用了所有的一面,第一個listview佔據了所有其他的??? – PropK 2013-03-25 13:12:35

+0

該頁面無xml @MKJParekh – PropK 2013-03-25 14:17:20

+0

轉發@MKJParekh ?? – PropK 2013-03-25 14:27:28

2

嘗試用LinearLayout中改變RelativeLayout的,請看一看這個link有關不同類型的佈局有了更深的瞭解。

1

嘗試使用weightSum 並將您的線性佈局添加到相對佈局中以獲得更好的定位。

相關問題