2017-05-20 168 views
-2

我有android的xml設計代碼。我希望設計有點不同。以下是相對佈局是我曾嘗試:Android XML佈局設計

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="sg.unitconverter.UnitFuel" 
    tools:showIn="@layout/activity_unit_fuel"> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/item1" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"/> 

    <Spinner 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/spinner1" 
     android:layout_below="@+id/item1" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:entries="@array/area"/> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/item2" 
     android:layout_below="@+id/spinner1" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <Spinner 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/spinner2" 
     android:layout_below="@+id/item2" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:entries="@array/area"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/clear" 
     android:id="@+id/clear" 
     android:layout_below="@+id/spinner2" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:onClick="onClick"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/backspace" 
     android:id="@+id/backSpace" 
     android:layout_below="@+id/spinner2" 
     android:layout_toRightOf="@+id/clear" 
     android:layout_toEndOf="@+id/clear" 
     android:onClick="onClick"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="7" 
     android:id="@+id/num7" 
     android:layout_below="@+id/clear" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:onClick="onClick"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="8" 
     android:id="@+id/num8" 
     android:layout_alignBottom="@+id/num7" 
     android:layout_alignLeft="@+id/backSpace" 
     android:layout_alignStart="@+id/backSpace" 
     android:onClick="onClick"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="9" 
     android:id="@+id/num9" 
     android:layout_alignBottom="@+id/num8" 
     android:layout_toRightOf="@+id/num8" 
     android:layout_toEndOf="@+id/num8" 
     android:onClick="onClick"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="4" 
     android:id="@+id/num4" 
     android:layout_below="@+id/num7" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:nestedScrollingEnabled="true" 
     android:onClick="onClick" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="5" 
     android:id="@+id/num5" 
     android:layout_alignBottom="@+id/num4" 
     android:layout_alignLeft="@+id/num8" 
     android:layout_alignStart="@+id/num8" 
     android:onClick="onClick" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="6" 
     android:id="@+id/num6" 
     android:layout_alignBottom="@+id/num5" 
     android:layout_toRightOf="@+id/num5" 
     android:layout_toEndOf="@+id/num5" 
     android:onClick="onClick" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="1" 
     android:id="@+id/num1" 
     android:layout_below="@+id/num4" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:onClick="onClick" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="2" 
     android:id="@+id/num2" 
     android:layout_alignBottom="@+id/num1" 
     android:layout_alignLeft="@+id/num5" 
     android:layout_alignStart="@+id/num5" 
     android:onClick="onClick" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="3" 
     android:id="@+id/num3" 
     android:layout_alignBottom="@+id/num2" 
     android:layout_toRightOf="@+id/num2" 
     android:layout_toEndOf="@+id/num2" 
     android:onClick="onClick" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="0" 
     android:id="@+id/num0" 
     android:layout_below="@+id/num2" 
     android:layout_alignLeft="@+id/num2" 
     android:layout_alignStart="@+id/num2" 
     android:onClick="onClick" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="." 
     android:id="@+id/dot" 
     android:textSize="20dp" 
     android:onClick="onClick" 
     android:layout_alignTop="@+id/num0" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="=" 
     android:id="@+id/equal" 
     android:onClick="onClick" 
     android:layout_alignTop="@+id/num0" 
     android:layout_alignLeft="@+id/num3" 
     android:layout_alignStart="@+id/num3" /> 
</RelativeLayout> 

上面的XML輸出顯示如下所示: enter image description here

但我想設計是這樣的: enter image description here

任何人都可以請這個幫忙做至少一件事,這樣會很棒嗎?

回答

0

在這裏你去..這只是基本的佈局..您需要的顏色和自定義它通過你的自我

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:orientation="horizontal"> 
     <TextView 
      android:layout_width="50dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="top" 
      android:layout_marginTop="10dp" 
      android:text="From"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      /> 

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

     </Spinner> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:orientation="horizontal"> 
     <TextView 
      android:layout_width="50dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="top" 
      android:layout_marginTop="10dp" 
      android:text="To"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1"/> 

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

     </Spinner> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:orientation="vertical"> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:orientation="vertical"> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:orientation="vertical"> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:orientation="vertical"> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:text="1" 
       style="?attr/borderlessButtonStyle" /> 

     </LinearLayout> 

    </LinearLayout> 
</LinearLayout> 
+0

謝謝你許多 – userash