简体   繁体   中英

How can I get text to show up in my rectangle, but I can't even get the rectangle to show?

Im trying to get this code to work for my android app, but I can't get my rectangle to show up and I don't know how to put text into this rectangle.

This is my shape.xml file

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

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

    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" 
     android:topLeftRadius="7dp" android:topRightRadius="7dp"/>  
</shape>

This is my fragment_task.xml

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/shape"
        android:orientation="vertical"
        android:layout_marginRight="10dp"   
        android:id="@+id/linearLayout">

    </LinearLayout>

</GridLayout>

The linear layout is set to wrap content and has nothing inside. What you probably want to do is putting the text view into the linear layout, so simplty move it, or just remove the linear layout and set the textview background to your drawable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM