2017-03-02 82 views
-1

我想这样做:enter image description hereJava的Android的框架布局

我这样做:

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/activity_aplication_settings" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#e2e2e2" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     tools:context="com.smok.maps.AplicationSettings"> 

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

      <TextView 
       android:id="@+id/textSync" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="#000000" 
       android:text="@string/sync" /> 

      <LinearLayout 
       android:id="@+id/line1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/textSync"> 

       <TextView 
        android:id="@+id/actual" 
        android:layout_width="wrap_content" 
        android:textColor="#000000" 
        android:layout_height="wrap_content" 
        android:text="@string/actual" /> 

       <EditText 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/count" /> 

       <TextView 
        android:id="@+id/actual2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textColor="#000000" 
        android:text="min" /> 
      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/lin2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/line1" 
       android:orientation="horizontal"> 

       <CheckBox 
        android:id="@+id/checkBox1" 
        android:layout_width="50dp" 
        android:layout_height="50dp" 
        android:button="@xml/setting_checkbox" 
        android:focusable="false" 
        android:gravity="center" /> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:src="@drawable/point" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:gravity="center" 
        android:textColor="#000000" 
        android:text="@string/show_choose_point" /> 

      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/lin3" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/lin2" 
       android:orientation="horizontal"> 

       <CheckBox 
        android:id="@+id/checkBox2" 
        android:layout_width="50dp" 
        android:layout_height="50dp" 
        android:button="@xml/setting_checkbox" 
        android:focusable="false" 
        android:gravity="center" /> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:src="@drawable/sync" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:textColor="#000000" 
        android:gravity="center" 
        android:text="@string/sync_request" /> 

      </LinearLayout> 
      <LinearLayout 
       android:id="@+id/lin4" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/lin3" 
       android:orientation="horizontal"> 

       <CheckBox 
        android:id="@+id/checkBox3" 
        android:layout_width="50dp" 
        android:layout_height="50dp" 
        android:button="@xml/setting_checkbox" 
        android:focusable="false" 
        android:gravity="center" /> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:src="@drawable/show_chooce" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:textColor="#000000" 
        android:gravity="center" 
        android:text="@string/show_choosen_points" /> 

      </LinearLayout> 
      <LinearLayout 
       android:id="@+id/lin5" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/lin4" 
       android:orientation="horizontal"> 

       <CheckBox 
        android:id="@+id/checkBox4" 
        android:layout_width="50dp" 
        android:layout_height="50dp" 
        android:button="@xml/setting_checkbox" 
        android:focusable="false" 
        android:gravity="center" /> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:src="@drawable/position2" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:gravity="center" 
        android:textColor="#000000" 
        android:text="@string/current_location" /> 

      </LinearLayout> 



    </RelativeLayout> 
    <LinearLayout 
     android:id="@+id/LinearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/back_bt" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:textColor="#ffffff" 
      android:background="@xml/roundedbutton" 
      android:text="@string/back" /> 

     <View 
      android:layout_width="0dp" 
      android:layout_weight="0.1" 
      android:layout_height="match_parent"> 

     </View> 

     <Button 
      android:id="@+id/confirm_bt" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:textColor="#ffffff" 
      android:background="@xml/roundedbutton" 
      android:text="@string/save" /> 
    </LinearLayout> 
</RelativeLayout> 

我不知道我该怎么办边境。我想做一个边框,在中间我想要放置文字的位置。这与屏幕上的相同。这看起来像一个有文字的框架。现在我有了文字,我不知道如何创建一个框架。

回答

1

的下面是你需要的演示。

1)您需要创建一个border.xml。把它放在你的可绘制文件夹中。添加以下代码在border.xml:

<?xml version="1.0" encoding="utf-8"?> 

<shape xmlns:android="http://schemas.android.com/apk/res/android" 

    android:shape="rectangle"> 

    <!--stroke width and color--> 

    <stroke 

     android:width="2dp" 

     android:color="@android:color/darker_gray" /> 

    <!-- corner radius--> 

    <corners 

     android:radius="5dp" /> 

    <!--paddings--> 

    <padding 

     android:bottom="1dp" 

     android:left="1dp" 

     android:right="1dp" 

     android:top="1dp" /> 

</shape> 

2)这里是layout.xml把背景相应一个的LinearLayout:

<?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="bd.com.tahsin.myapplicationnavgroup.MainActivity" 
    tools:showIn="@layout/app_bar_main"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:weightSum="1" 
     android:layout_marginTop="5dp"> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="0.3" 
      android:background="@drawable/bottom_border_help"> 

     </LinearLayout> 

    </LinearLayout> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="MENU_BOCZNE" 
     android:background="@color/background_floating_material_light" 
     android:layout_marginLeft="10dp" /> 

</RelativeLayout> 

3)最后的屏幕截图:

enter image description here

希望,这会有所帮助。

1

试试这个,

 <?xml version="1.0" encoding="utf-8"?> 
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_margin="15dp" > 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/border" 
       android:layout_marginTop="10dp" 
       android:orientation="vertical" 
       android:padding="15dp"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textStyle="bold" 
        android:text="TEST"/> 

      </LinearLayout> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:text=" MENU " 
       android:layout_marginLeft="15dp" 
       android:background="#ffffff" 
       android:textSize="17sp" /> 

     </RelativeLayout> 

XML border.xml

<?xml version="1.0" encoding="utf-8"?> 

    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle" > 
     <corners android:radius="3dp"/> 
     <stroke 
      android:width="2dp" 

      android:color="#cdcdcd" /> 
    </shape>