简体   繁体   English

一个带有图像和文字的小部件

[英]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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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