- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在 2 个 EditText 的右边有一个 ImageButton
我试过了
RelativeLayout
:但是 ImageView layout_height="match_parent"
不起作用
LinearLayout
:但无法在不被 EditText 推出的情况下将按钮移至右侧。 LinearLayout 的 LayoutDirection="rtl"
本来可以工作,但它不再存在了
编辑:
我不想在宽度/高度上使用特定值
我有这个,我现在把高度设置为 90dp,但我不想让它放在那里
<RelativeLayout
android:id="@+id/login_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" >
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username"
android:layout_toLeftOf="@id/login"
android:inputType="text"
android:gravity="center_horizontal" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"
android:layout_below="@id/username"
android:layout_toLeftOf="@id/login"
android:inputType="textPassword"
android:gravity="center_horizontal" />
<!-- TODO: FIX android:layout_height="match_parent" -->
<ImageButton
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="90dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:contentDescription="@string/login"
android:scaleType="fitCenter"
android:src="@drawable/login_button" />
</RelativeLayout>
最佳答案
您可以使用以下之一:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/edtxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions" />
<ImageButton
android:id="@+id/imgv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/edtxt"
android:contentDescription="@string/saveBtn"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
或
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:orientation="horizontal"
android:weightSum="2" >
<EditText
android:id="@+id/edt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<ImageButton
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
</LinearLayout>
编辑:
我更新了你的代码。检查一下。它在我的模拟器中显示了你想要的输出。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/login_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" >
<ImageButton
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:contentDescription="@string/username"
android:src="@drawable/ic_launcher" />
<EditText
android:id="@+id/uname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/login"
android:gravity="center_horizontal"
android:hint="@string/username"
android:inputType="text" />
<EditText
android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/uname"
android:layout_toLeftOf="@id/login"
android:gravity="center_horizontal"
android:hint="@string/password"
android:inputType="textPassword" />
</RelativeLayout>
输出:
关于android如何使用layout_height ="match_parent"将Imagebutton放在右边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13472896/
我必须为 IE11 编写一些网格回退。 我想将元素 4 放在右下角,以便元素 1 可以一直向下延伸到底部吗? 我认为这对 flexbox 来说是不可能的,对吧? : https://jsfiddle.
您好,我正在尝试让 2 个 div 在左侧与右侧对齐。 #div1 #div2 #div1 #div2 #div3 #div2 #div3 #div3 诀窍是当浏览器窗口变小时,我希望#div2 位于
如何才能点击 EditText 的右侧可绘制对象(查看屏幕截图)?我尝试了几种方法,但总是卡住。 public static Matcher withEditTextDrawable(final in
这个问题在这里已经有了答案: In CSS Flexbox, why are there no "justify-items" and "justify-self" properties? (6
所以我有 10 个复选框,每个标签都取自数组中相应的索引。我正在使用 ng-repeat 来展示它们: {{entity}}
我是一名优秀的程序员,十分优秀!