2014-01-10 89 views
0

我想設置我的android XML這樣http://i.imgur.com/BJZAEaZ.png和我的佈局必須是非常可縮放的所有不同的android屏幕尺寸也需要與所有不同的工作Android版本。屏幕將被鎖定在橫向視圖中,因此您不必擔心縱向視圖。第一組(常規小時數以上)需要一起擴大和縮小以及加班時間。同樣在垂直居中設置完整報告。每組數字/文本都需要在自己的文本視圖中,以便我可以單獨設計它們。會因爲某種原因而對此有所幫助,所以我無法將我的思想包圍在裏面。我對Android XML相當陌生。我嘗試了不同的佈局相對不能根據不同的屏幕尺寸進行縮放,並且由於所有不同的文本視圖和「完整報告」鏈接的關閉,網格佈局給我帶來了很多麻煩。 所以期待解決方案。謝謝你爲今後的任何幫助。(這裏是我與我的代碼現在。)試圖設置我的Android Xml佈局縮放工作

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#ffe4e4e4" 
> 
<View android:layout_width="fill_parent" 
    android:layout_height="1dp" 
    android:background="#ffa9a9a9" 
    /> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="4dp" 
    android:paddingRight="4dp" 
    android:background="#ffd1d1d1" 
    android:src="@drawable/top_bottom_border"> 

    <LinearLayout 
     android:id="@+id/row_1" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 

     > 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="4dp" 
      android:text="40" 
      android:textSize="20sp"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="4dp" 
      android:text="hrs"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="4dp" 
      android:text="30" 

      android:textSize="20sp" 
      /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="min" 
      android:layout_marginRight="14dp"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Regular" 
      android:textSize="14sp" 
      android:layout_marginRight="4dp" 
      /> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="View Time Log" 
      android:layout_marginRight="4dp" 
      android:textColor="#ff0009ff" 
      android:gravity="right"/> 


    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/row_2" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 

     > 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="4dp" 
      android:text="15" 

      android:textSize="20sp" 
      /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="hrs" 
      android:layout_marginRight="4dp"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="17" 

      android:textSize="20sp" 
      android:layout_marginRight="4dp"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="min" 
      android:layout_marginRight="14dp"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="OverTime" 
      android:textSize="14sp" 
      android:layout_marginRight="4dp"/> 


     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="right"> 


      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 

       android:layout_marginRight="2dp" 
       android:gravity="right"/> 


     </LinearLayout> 



    </LinearLayout> 

回答

0

也許你可以嘗試使用的LinearLayout,使用match_parent,像這樣。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 
</LinearLayout> 

然後填寫,但是你需要。這應該創建一個可擴展的視圖,每個項目佔用屏幕的三分之一。您可以根據需要調整android:layout_weight。我相信權重的總和是任意的,但是權重越高,屏幕尺寸將需要(weight)/(total_weight)。希望這可以幫助!

+0

的問題,我有與你的答案os有兩行文字,他們必須一起伸展你的兩個將工作,如果我只是在做一個單獨的行。這裏是,如果我的代碼是正確的,這可能會幫助你更好地理解(我將把代碼添加到頂端) – jared90

0

我會建議在封閉的三個要素一個RelativeLayout

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

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

    <Button 
     android:id="@+id/b1" 
     android:text="Button 1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true"   
     /> 

    <Button 
     android:id="@+id/b2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"   
     android:layout_centerHorizontal="true" 
     android:text="Button 2" /> 

    <Button 
     android:id="@+id/b3" 
     android:text="Button 3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true"   
     /> 


    </RelativeLayout> 

</LinearLayout> 

它的縱向和橫向的偉大工程:

enter image description here

enter image description here

+0

我認爲這不會起作用,它對於按鈕非常有用,但不適用於所有文本我正在使用的視圖以及我必須處理的不同行。 Plz看看上面的代碼,我剛剛添加它,我的幫助,你看到我是來自。 – jared90

+0

您可以將每個文本組包含在視圖中。這些視圖將替換佈局中的按鈕。但是,您的代碼幾乎不可讀,請嘗試爲您的元素添加一些ID,以便解碼,並且還可以發佈結果的屏幕截圖。 –