2016-12-14 70 views
0

我需要將border設置爲linearLayout而不修改其大小,我嘗試在linearLayout的背景中設置一些帶邊框和填充的drawable,但是這個設置在linearLayout內部並修改了大小,圖像和textView。您是否有設置邊界以外或重疊視圖的方式?佈局以外的邊框

我的代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/itemCarouselContainer" 
    android:layout_width="@dimen/carousel_item_width" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_marginRight="@dimen/carousel_item_margin_right" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <ImageView 
      android:id="@+id/imageCarousel" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/carousel_image_poster_height" 

      /> 

     <TextView 
      android:id="@+id/live" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginLeft="@dimen/carouse_item_live_margin_left" 
      android:layout_marginTop="@dimen/carousel_item_live_margin_top" 
      android:padding="@dimen/carousel_item_live_padding" 
      android:textColor="@color/carousel_live_text" 
      android:textSize="@dimen/carousel_item_live_text_size" 
      android:textStyle="bold" /> 
    </RelativeLayout> 

    <TextView 
     android:id="@+id/titleCarousel" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:background="@color/carousel_content_title_background" 
     android:gravity="center" 
     android:padding="7dp" 
     android:singleLine="true" 
     android:textColor="@color/carousel_content_title_text" 
     android:textSize="@dimen/carousel_title_size" /> 
</LinearLayout> 
+0

**否**。你不能在**視圖之外添加任何內容**(除非你添加一個容器視圖到它),只有**內**它。可能''padding'就是你要找的東西。 –

回答

1

爲繪製

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

    <stroke 
     android:width="1dp" 
     android:color="@color/miniBlack" 
     android:dashGap="10px" 
     android:dashWidth="10px"/> 
</shape> 

將它設置爲佈局的背景給它一個2dp padding所以stroke不會覆蓋內容

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/itemCarouselContainer" 
    android:layout_width="@dimen/carousel_item_width" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_marginRight="@dimen/carousel_item_margin_right" 
    android:orientation="vertical" 
    android:background="@drawable/myfile" 
    android:paddings="2dp" 
>... 
創建此