2014-04-05 59 views
3

在我的android应用程序中,我只需要四个角落的边框,如图(白色)所示。Android:边框只在角落

enter image description here

<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="6"> 
     <VideoView 
      android:id="@+id/video1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="center" /> 
     <View 
      android:layout_width="150dp" 
      android:layout_height="150dp" 
      android:layout_centerInParent="true" 
      android:background="@drawable/cornerbg" /> 
    </RelativeLayout> 

cornerbg.xml

 <?xml version="1.0" encoding="utf-8"?> 
     <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 

     <item> 
      <shape android:shape="rectangle" > 
       <solid android:color="@color/transparent" /> 
       <stroke 
        android:width="1dp" 
        android:color="@color/btn_border" 
        android:dashWidth="50dp" // I tried this but not getting expected 
        android:dashGap="60dp"/> 

      </shape> 
     </item> 
     </layer-list> 

我如何编写XML的呢?

请帮帮忙,谢谢

+0

你需要这些可见的角落,在里面的照片或作为边界? –

+1

创建该四角图像的9.png,并将其放置在图像的布局前面 –

+0

@fremmedehenvendelser在边框内。但我可以管理它,我不会将它写入xml。我将用axml和xml更新我的问题 –

回答

0

不幸的是,我不相信我用来完成这会为需要透明背景的视图的工作方法,但它应该在所有其他情况下工作。使用下面的代码简单地创建一个可绘制的资源,并将其设置为您希望具有“仅转角”边框的任何视图的背景。

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape android:shape="rectangle"> 
      <solid android:color="@android:color/white" /> 
     </shape> 
    </item> 
    <item 
     android:left="10dp" 
     android:right="10dp"> 
     <shape android:shape="rectangle"> 
      <solid android:color="@android:color/black" /> 
     </shape> 
    </item> 
    <item 
     android:top="10dp" 
     android:bottom="10dp"> 
     <shape android:shape="rectangle"> 
      <solid android:color="@android:color/black" /> 
     </shape> 
    </item> 
    <item 
     android:left="2dp" 
     android:right="2dp" 
     android:bottom="2dp" 
     android:top="2dp"> 
     <shape android:shape="rectangle"> 
      <solid android:color="@android:color/black" /> 
     </shape> 
    </item> 
</layer-list> 
0

我知道这是很久以前的问题,但我有同样的问题。

我解决了创建二次布局和包括在我的主布局。

我希望这个解决方案可以帮助别人。

main_layout.xml

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="0dip" 
    android:layout_weight="6"> 

    <VideoView 
     android:id="@+id/video1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center" /> 

    <include layout="@layout/camera_box_layout" /> 

</RelativeLayout> 

camera_box_layout.xml

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="40dp" 
    android:background="@android:color/transparent"> 

    <!-- Top horizzontal lines --> 
    <View 
     android:layout_width="100dp" 
     android:layout_height="2dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentStart="true" 
     android:background="@android:color/darker_gray" /> 

    <View 
     android:layout_width="100dp" 
     android:layout_height="2dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentEnd="true" 
     android:background="@android:color/darker_gray" /> 

    <!-- Top vertical lines --> 
    <View 
     android:layout_width="2dp" 
     android:layout_height="100dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentStart="true" 
     android:background="@android:color/darker_gray" /> 

    <View 
     android:layout_width="2dp" 
     android:layout_height="100dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentEnd="true" 
     android:background="@android:color/darker_gray" /> 

    <!-- Bottom horizzontal lines --> 
    <View 
     android:layout_width="100dp" 
     android:layout_height="2dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentStart="true" 
     android:background="@android:color/darker_gray" /> 

    <View 
     android:layout_width="100dp" 
     android:layout_height="2dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:background="@android:color/darker_gray" /> 

    <!-- Bottom vertical lines --> 
    <View 
     android:layout_width="2dp" 
     android:layout_height="100dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentStart="true" 
     android:background="@android:color/darker_gray" /> 

    <View 
     android:layout_width="2dp" 
     android:layout_height="100dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:background="@android:color/darker_gray" /> 
</RelativeLayout>