【问题标题】:ImageView should appear under the textView but is not happening in the given layoutImageView 应该出现在 textView 下,但在给定的布局中没有发生
【发布时间】:2015-08-07 09:54:25
【问题描述】:

这段代码不能正常工作,TextView 应该出现在 ImageView 上,请告诉我哪里错了。我只是一个初学者,很抱歉有任何愚蠢的问题。

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="250dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="Memorable Shaadi"
        android:textColor="#fff"
        android:textSize="20sp"
        android:textStyle="bold|italic" />

    <ImageView
        android:id="@+id/main_img"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:background="@drawable/main_img" />
</RelativeLayout>

</RelativeLayout>

【问题讨论】:

  • 你为什么要修复 ImageView 的大小。?你能发布你的设计屏幕截图吗?
  • 我的问题解决了,谢谢回复

标签: android xml textview imageview


【解决方案1】:

试试这个

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="250dp">



<ImageView
    android:id="@+id/main_img"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:background="@drawable/main_img" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    android:text="Memorable Shaadi"
    android:textColor="#fff"
    android:textSize="20sp"
    android:textStyle="bold|italic" />
</RelativeLayout>

交换你的 textview 和 imageview

【讨论】:

    【解决方案2】:

    您的问题在于您将视图添加到RelativeLayout 的顺序。将其视为层。如果您希望 TextView 在顶部,则应添加的最后一个视图是 TextView。

    试试这样:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="250dp">
    
        <ImageView
            android:id="@+id/main_img"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:background="@drawable/main_img" />
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp"
            android:text="Memorable Shaadi"
            android:textColor="#fff"
            android:textSize="20sp"
            android:textStyle="bold|italic" />
    </RelativeLayout>
    

    【讨论】:

      【解决方案3】:

      如果你想在相对布局中在另一个下面添加任何组件,你必须声明 android:layout_below="@id/idOfTheComponentAbove"

      在线性布局中,您必须相应地按顺序放置它们

      【讨论】:

        【解决方案4】:

        您可以将 imageview 和 textview 放在一个线性布局中,并将其方向设置为垂直

        <LinearLayout
            android:id="@+id/otpView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
             >
        
             <TextView 
                 android:id="@+id/helpText"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="@string/text_otp_help"
                 android:layout_marginTop="10dp"
                 android:textColor="@color/white"
                 android:textSize="15sp"
                 android:layout_gravity="center_horizontal"
                 />
                 <ImageView
                    android:id="@+id/imageViewMessageIcon"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:contentDescription="@string/message_icon"
                    android:src="@drawable/icon_mark" />
        
        </LinearLayout>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-07
          • 2015-02-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多