2012-12-11 4 views
4

여기에 제 코드가 있습니다. TextView의 4 가지 테두리를위한 파란색 디자인입니다. 내가 원하는 것은 3 개의 테두리 (위쪽, 왼쪽 및 아래쪽)에 대해서만 디자인하는 것입니다. 1DP의 높이의 맨 아래에 배치 코드 아래TextView의 왼쪽, 위쪽 및 아래쪽 경계선 방법

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" > 
     <shape> 
      <solid 
       android:color="#449def" /> 
      <stroke 
       android:width="1dp" 
       android:color="#2f6699" /> 
      <corners 
       android:radius="0dp" /> 
      <padding 
       android:left="5dp" 
       android:top="5dp" 
       android:right="5dp" 
       android:bottom="5dp" /> 
     </shape> 
    </item> 
    <item> 
     <shape> 
      <gradient 
       android:startColor="#ffffff" 
       android:endColor="#ffffff" 
       android:angle="270" /> 
      <stroke 
       android:width="1dp" 
       android:color="#2f6699" /> 
      <corners 
       android:radius="0dp" /> 
      <padding 
       android:left="5dp" 
       android:top="5dp" 
       android:right="5dp" 
       android:bottom="5dp" /> 
     </shape> 
    </item> 
</selector> 
+0

같은 시도 http://stackoverflow.com/questions/5254562/is-there-a-simpler-better-way-to-put-a-border-outline-around-my -textview – RobinHood

답변

2

이것은 빠른 해결책입니다 (참조), TextViewandroid:translationX="2dp"을 추가하고 분실 한 공간을 보충하기 위해 android:paddingRight="2dp"을 추가 할 수 있습니다.

8

, 다른 측면

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

<!-- This is the line --> 
<item> 
    <shape> 
     <solid android:color="#535353" /> 
    </shape> 
</item> 

<!-- This is the main color --> 
<item android:bottom="1dp"> 
<shape> 
     <solid android:color="#252525" /> 
</shape> 
</item> 
</layer-list> 

이 함께 플레이 할 필요가 바보 아마이 토론 Open-sided Android stroke?

+1

줄과 주된 색깔이 당신이 준 링크에서 다르다. 나는 너의 것이 틀렸다고 생각한다. 댓글을 변경해야합니다. –

1

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape> 
      <padding android:bottom="1dp" android:left="1dp" android:right="0dp" 
       android:top="1dp"/> 
      <solid android:color="#000"/> 
     </shape> 
    </item> 

    <!-- Background --> 
    <item> 
     <shape> 
      <solid android:color="@color/white"/> 

     </shape> 
    </item> 
</layer-list> 
관련 문제