简体   繁体   中英

A widget with image and text below

I want to create a widget with image and text below image. widget i want

If I write this code:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/myImageView"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:src="@drawable/cat1" />
    <TextView
        android:id="@+id/text_widget"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:background="#808080"
        android:text="@string/widget_text"/>

</LinearLayout>

I have an image without text. And I want to known how to do a widget if the text could be variable lenght

If I use Relative layout the text is above the Image

The text will below the image

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/myImageView"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:src="@drawable/cat1" />

    <TextView
        android:id="@+id/text_widget"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="150dp"
        android:background="#808080"
        android:gravity="center"
        android:text="@string/widget_text"
        android:textColor="#000"
        android:textSize="18sp" />

</RelativeLayout>

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