2017-02-22 22 views
0

border.xmlテキストビューの周りに境界線を置く方法は? (描画可能フォルダ内)

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <shape xmlns:android="http://schemas.android.com/apk/ res/android"> 
    <stroke android:width="2dp" 
      android:color="#000"/> 

    <corners android:radius="10dp" /> 

    <padding android:left="10dp" 
      android:top="5dp" 
      android:right="10dp" 
      android:bottom="5dp"/> 

    </shape> 
</selector> 

activity_main.xml

<TextView 
    android:id="@+id/textView" 
    android:layout_width="100dp" 
    android:layout_height="20dp" 
    android:layout_marginBottom="16dp" 
    android:layout_marginEnd="16dp" 
    android:layout_marginLeft="16dp" 
    android:layout_marginRight="16dp" 
    android:layout_marginStart="16dp" 
    android:layout_marginTop="16dp" 
    android:background="@drawable/border" 
    android:text="TextView" 
    android:textSize="20sp" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent"/> 

私は上記のコードを使用してのTextViewに境界線を取得することができません。制約レイアウトの幅と高さは、match_parentに設定されています。

+1

コンテンツをラップするために幅と高さを設定します。 TextViewから制約を削除する –

+0

border.xmlからセレクタとパディングを削除する –

+0

@ZakiPathan動作しません。それを試してみました。 –

答えて

0

あなたはborder.xmlファイルが間違っていると思います。

はこれでテストをやってみてください。

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > 
    <solid android:color="#ffffff" /> 
    <stroke android:width="1dip" android:color="#4fa5d5"/> 
</shape> 

それは構文で何か間違っていることを意味動作するかどうか。 (おそらくセレクターをひどく使いました)

+0

ありがとうございます。私は間違いを犯しましたシェイプタグにresの前にスペースがあります! –

関連する問題