2013-07-23 40 views
1

這是我的項目的示例adndroid佈局,它在縱向視圖中看起來不錯,但在橫向模式下它不顯示所有佈局組件。未顯示Android中的所有佈局組件

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 

android:fillViewport="true" > 

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:background="#696969" 
     android:gravity="center" 
     android:lines="1" 
     android:text="BAR 1" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@+id/textView2" 
     android:layout_below="@+id/textView1" 
     android:scrollbars="horizontal" > 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:text="T" 
      android:textSize="40sp" /> 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/button2" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="16dp" 
      android:text="Not" /> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/textView3" 
      android:layout_alignTop="@+id/button2" 
      android:layout_marginRight="22dp" 
      android:layout_toLeftOf="@+id/button2" 
      android:text="T" 
      android:textSize="40sp" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/textView3" 
      android:layout_alignTop="@+id/button2" 
      android:layout_marginLeft="20dp" 
      android:layout_toRightOf="@+id/button2" 
      android:text="T" 
      android:textSize="40sp" /> 

     <TextView 
      android:id="@+id/textView4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/textView3" 
      android:layout_alignBottom="@+id/textView3" 
      android:layout_alignLeft="@+id/button3" 
      android:layout_alignRight="@+id/button3" 
      android:text="Working" /> 

     <TextView 
      android:id="@+id/textView5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/textView3" 
      android:layout_alignBottom="@+id/textView3" 
      android:layout_alignLeft="@+id/button1" 
      android:layout_alignRight="@+id/button1" 
      android:text="Why" /> 

    </RelativeLayout> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:background="#696969" 
     android:gravity="center" 
     android:lines="1" 
     android:text="BAR 2" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 
</RelativeLayout> 

</ScrollView> 

縱向視圖 http://i.stack.imgur.com/XlVlx.png

橫向視圖 http://i.stack.imgur.com/DfMVA.png

我必須使用Android:fillViewport = 「真」 爲擴大布局,請幫我解決這個問題。在橫向模式下

  • 滾動

    1. 顯示完整佈局不工作

    感謝。

    解決方案:)

    <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" > 
    
        <LinearLayout 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:orientation="vertical" > 
    
         <TextView 
          android:id="@+id/textView1" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:background="@drawable/test" 
          android:lines="1" 
          android:text="@string/bar_1" 
          android:textAppearance="?android:attr/textAppearanceLarge" /> 
    
         <RelativeLayout 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" > 
    
          <TextView 
           android:id="@+id/textView3" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_alignLeft="@+id/button2" 
           android:layout_alignRight="@+id/button2" 
           android:layout_below="@+id/button2" 
           android:layout_marginTop="15dp" 
           android:text="TextView" /> 
    
          <Button 
           android:id="@+id/button2" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_centerHorizontal="true" 
           android:layout_centerVertical="true" 
           android:layout_marginTop="15dp" 
           android:gravity="center" 
           android:padding="10dp" 
           android:paddingLeft="10dp" 
           android:paddingRight="10dp" 
           android:text="T" 
           android:textSize="40sp" /> 
         </RelativeLayout> 
        </LinearLayout> 
    
        <LinearLayout 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginTop="15dp" 
         android:orientation="vertical" > 
    
         <TextView 
          android:id="@+id/textView1" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:background="@drawable/test" 
          android:lines="1" 
          android:text="@string/bar_1" 
          android:textAppearance="?android:attr/textAppearanceLarge" /> 
    
         <RelativeLayout 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" > 
    
          <TextView 
           android:id="@+id/textView3" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_alignLeft="@+id/button2" 
           android:layout_alignRight="@+id/button2" 
           android:layout_below="@+id/button2" 
           android:layout_marginTop="16dp" 
           android:text="TextView" /> 
    
          <Button 
           android:id="@+id/button2" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_alignParentTop="true" 
           android:layout_centerHorizontal="true" 
           android:layout_marginTop="15dp" 
           android:gravity="center" 
           android:text="T" 
           android:textSize="40sp" /> 
         </RelativeLayout> 
        </LinearLayout> 
    </LinearLayout> 
    
    </ScrollView> 
    
  • +0

    請爲兩個oriantation做出不同的佈局 – KOTIOS

    +0

    嵌套佈局對性能不利(http://developer.android.com/training/improving-layouts/optimizing-layout.html)。改爲使用單個RelativeLayout會更好。 –

    回答

    0

    沒有足夠的空間來放置TextViews,你可以嘗試創建與放置在一旁的textviews新的佈局,或者把一切都放在一個滾動視圖

    2

    您的textView2以垂直居中顯示,因此它始終位於佈局的中間。 在縱向上,它將自己放在前面的文字上。

    爲什麼不使用帶垂直方向的LinearLayout?

    +0

    謝謝!是的LinearLayout會做 – mahbubzaman