android - 如何将带有图像的圆形 TextView 放置在透明图像android附近?`

标签 android android-layout android-imageview android-relativelayout

如何将带有两个 TextView 的圆形图像靠近透明图像下方?我用 TextView 创建了透明图像,但我不知道如何用两个 TextView (即日期和日期)放置圆形图像。 如何达到预期的产出?

预期输出是: enter image description here

这是我的代码。

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#AAA" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/overlay_margin"
        android:background="#FFF" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/salogo" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#7000"
            android:orientation="vertical"
            android:paddingBottom="15dp"
            android:paddingTop="15dp" >
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Marathon for organ donation"
                android:textColor="#CCC"
                android:textSize="12sp"/>
            </LinearLayout>
    </RelativeLayout>
   </LinearLayout>
    </ScrollView>

但我得到的输出是: enter image description here

最佳答案

drawable文件夹中创建circular_bg.xml 并写..

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
<gradient
    android:endColor="#3399FF"
    android:startColor="#3399FF" />

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

</shape>

现在在你的 xml 中

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:padding="2dp" >
        <TextView
            android:id="@+id/text"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:text="31 sun"
            android:layout_centerInParent="true"
            android:background="@drawable/circular_bg"
            android:gravity="center"
            android:textColor="#ffffff"
            android:textStyle="bold" />

</RelativeLayout>

它会解决你的问题。

关于android - 如何将带有图像的圆形 TextView 放置在透明图像android附近?`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27775543/

相关文章:

Android MediaPlayer 问题 :"Error (-38 , 0) "和 "stop called in state 1"

带有图标的 Android 圆形按钮

android - 应用程序启动时删除文本框的初始焦点?

android - ImageView 中的动画位图(模拟报亭应用程序 - Ken Burns Effect)

android - System.out resolveUri 在错误的位图 uri : https://. 上失败 .. 当我尝试将图片从 Web 插入到 ListView 时

java - 需要使用看起来很奇怪的 Schema 来解析 XML

android - 适用于 Android 2.2 的动态 C/C++ 库 : error Symbol not found

由于插件错误,Android 构建失败

android - 组合文本和图像按钮,调整可绘制大小

android - Facebook Messenger 如何绘制聊天头? (安卓)