java - 布局中 ImageView 上方的 TextView

标签 java android android-layout

我正在为我的屏幕使用此布局:

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" android:background="@drawable/tmp" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/uph" 
        android:layout_gravity="top|center" android:layout_marginTop="-10dp"/>

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/propfile" 
        android:layout_gravity="top|center"/>    
</LinearLayout>

我想在 imageView2 上方的屏幕上添加一个 TextView。

当我将它添加到 xml 时,它会显示在图像下方。 我需要做什么才能将 TextView 放在图像上。

最佳答案

试试这个:

    <?xml version="1.0" encoding="utf-8"?> 
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" android:background="@drawable/tmp" >


        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/uph" 
             android:layout_marginTop="-10dp"/>

        <RelativeLayout  android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:layout_gravity="top|center">

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/propfile" 
            />

           <TextView  android:layout_width="wrap_content"
               android:layout_height="wrap_content" 
               android:text="text" 
               android:layout_centerInParent="true"
           /> 
      </RelativeLayout>   
    </LinearLayout>

关于java - 布局中 ImageView 上方的 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9539772/

相关文章:

java - 有没有办法在php中使用交换加密?

java - 如何使用JAVA获取局域网IP地址

java - 将 SQLite 与我的 Java EE 应用程序集成的正确方法是什么?

java - array.sort 如何处理多维数组?

java - JNI "jobject thiz"与jboolean参数关系

c# - 自升级到 Visual Studio 2017 15.3.0 后,应用程序中出现奇怪的调试输出

android - 我需要帮助向 glSurfaceView 添加第二个纹理

android - 是否可以在水平方向的布局编辑器中显示 RecyclerView 预览?

安卓 : LinearLayout with 2 buttons at the bottom

android - 带有图标或图像的 ImageButton 中未显示文本