【问题标题】:’android:paddingRight’ working with ‘android:drawableRight’'android:paddingRight' 与'android:drawableRight' 一起使用
【发布时间】:2012-07-04 17:22:20
【问题描述】:

在 EditText 中,我在 EditText 的右侧放了一张图片, 我使用 FrameLayout 添加一个文本视图,显示 Edittext 的剩余输入计数(如 p1 所示)。

但是当输入太长时,它会与文本视图重叠,为了避免这种情况,我想使用 android:paddingRight 保持输入字符保持在左边,但结果就像 p2

如何使可绘制图标保持在右侧,仅输入字符,如 p3? 谢谢。

【问题讨论】:

  • 为此使用RelativeLayout。好多了。
  • 你能分享上述布局的xml吗

标签: android android-edittext padding


【解决方案1】:

您应该使用 RelativeLayout 而不是在 LinearLayout 中的文本之后附加按钮。

Android RelativeLayouts 的资源可以在以下位置找到:http://developer.android.com/guide/topics/ui/layout/relative.html

这篇文章值得一读

但一般原则是您可以定义如下内容:

<Button
    android:id="@+id/button"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_below="@id/name"
    android:layout_alignParentLeft="true"
    android:layout_toLeftOf="@+id/times" />

注意上面的layout_belowlayout_toLeftOf,它们定义了相对于其他对象的定位

【讨论】:

    【解决方案2】:

    使用 ImageSpan 在 EditView 中添加 Image 而不是在 Layout 中设置

    【讨论】:

      【解决方案3】:

      这应该是一个替代示例,使用RelativeLayout:

       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent">
      
           <EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:layout_alignParentLeft="true" android:layout_centerHorizontal="true"
                android:paddingRight="30dp"
                />
      
      
           <ImageView android:layout_width="20dp" android:layout_height="20dp"
               android:src="@drawable/your_image"
               android:layout_alignParentRight="true" android:layout_centerHorizontal="true"
               />
      
       </RelativeLayout>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-06-16
        • 1970-01-01
        • 2019-02-21
        • 2014-03-20
        • 1970-01-01
        • 2016-08-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多