2012-05-04 17 views
1

如何在視圖框中的XML代碼中包裝元素?這意味着我希望他們看起來像是將他們分組在有邊框的盒子裏。在xml中將視圖包裝在一個框中

<Button 
    android:id="@+id/carbgraph" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_x="230dp" 
    android:layout_y="378dp" 
    android:text="Button" /> 

<ProgressBar 
    android:id="@+id/progressBarforcals" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="280dp" 
    android:layout_height="wrap_content" 
    android:layout_x="15dp" 
    android:layout_y="346dp" /> 

<TextView 
    android:id="@+id/calsinmenu" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_x="16dp" 
    android:layout_y="320dp" 
    android:text="TextView" /> 

回答

3

把你的小部件的佈局(LinearLayout中爲例),並編輯下面這個佈局背景:

<LinearLayout 
    ... 
    android:background="@drawable/background" 
</LinearLayout> 

然後在你的文件夾繪製創建一個XML文件命名background.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <stroke 
     android:width="3dp" 
     android:color="#838c7f"> 
    </stroke> 

    <padding 
     android:left="3dp" 
     android:top="3dp" 
    android:right="3dp" 
    android:bottom="3dp"> 
    </padding> 

    <corners android:radius="4dp" /> 

    <gradient 
     android:startColor="@color/background_start" 
     android:endColor="@color/background_end"/> 
</shape> 
0
You can set background of your layout 

創建一個圖像,看起來像框的邊框名爲box.png put此圖像可繪製

ex: 

    <LinearLayout 
    .. .. 
     android:backgroud="@drawable/box.png"> 

<Button 
    android:id="@+id/carbgraph" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_x="230dp" 
    android:layout_y="378dp" 
    android:text="Button" /> 

<ProgressBar 
    android:id="@+id/progressBarforcals" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="280dp" 
    android:layout_height="wrap_content" 
    android:layout_x="15dp" 
    android:layout_y="346dp" /> 

<TextView 
    android:id="@+id/calsinmenu" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_x="16dp" 
    android:layout_y="320dp" 
    android:text="TextView" /> 


    </LinearLayout> 
相關問題