android 将对象放置在 ImageView 下方

标签 android android-layout android-studio

我必须创建一个水平对齐的 TextView 和一个放置在另一个 ImageView 下方的 ImageView 。问题是它们没有水平对齐。我应该怎么做才能避免这个问题?..

现在发生了什么:
enter image description here

应该是这样的:
enter image description here

我的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:padding="5dp"
    >
    <ImageButton
        android:id="@+id/imgBtnItem"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:background="@android:color/transparent">
    </ImageButton>

    <TextView
        android:id="@+id/txtName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textSize="9sp"
        android:layout_below="@+id/imgBtnItem">
    </TextView>
    <ImageButton
        android:id="@+id/imgBtnAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imgBtnItem"
        android:layout_toRightOf="@+id/txtName"
        android:background="@android:color/transparent"
        >
    </ImageButton>
</RelativeLayout>

最佳答案

用作(根据用途编辑尺寸):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="5dp"
>
<ImageButton
    android:id="@+id/imgBtnItem"
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter"
    android:background="@color/colorAccent">
</ImageButton>

<TextView
    android:id="@+id/txtName"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:textStyle="bold"
    android:textSize="9sp"
    android:layout_marginTop="4dp"
    android:layout_below="@+id/imgBtnItem"
    android:background="@color/colorPrimary">
</TextView>
<ImageButton
    android:id="@+id/imgBtnAdd"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@color/colorPrimaryDark"
    android:layout_below="@+id/imgBtnItem"
    android:layout_alignTop="@id/txtName"
    android:layout_toEndOf="@id/txtName"
    android:layout_alignEnd="@+id/imgBtnItem">
</ImageButton>
</RelativeLayout>

输出:

enter image description here

关于android 将对象放置在 ImageView 下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41918499/

相关文章:

android - 如何在 onSaveInstanceState 中查看 Bundle 对象的大小?

java - 在 Java 中处理延迟事件的最佳方法是什么

android - 为什么我的自定义构建类型给出 apk not signed 错误

android - 中心景观线性布局android

android - 如何从 TextInputLayout 中删除白框

java - Android Studio中如何生成.so文件和对应的Java接口(interface)

android - 如何在 cmusphinx 上进行土耳其语语音识别?

java - 如何处理屏幕方向变化

android - 在 Android 中抓取帧视频到 Gif

android - 如何让 android ListView 项目选择器使用 state_pressed