Android 右对齐编辑文本-can';不要让它与任何属性对齐
我尝试了所有我能找到的方法来右对齐这个EditText元素,但它不会 我错过了什么?如您所见,我尝试了Android 右对齐编辑文本-can';不要让它与任何属性对齐,android,android-layout,Android,Android Layout,我尝试了所有我能找到的方法来右对齐这个EditText元素,但它不会 我错过了什么?如您所见,我尝试了android:layout\u alignParentRight=“true”和android:layout\u gravity=“right”,但没有任何运气 注:linearLayout只是具有RelativeLayout的父元素中的一个元素,但我想这并不重要 <LinearLayout android:id="@+id/block1" android:layout_width=
android:layout\u alignParentRight=“true”
和android:layout\u gravity=“right”
,但没有任何运气
注:linearLayout只是具有RelativeLayout的父元素中的一个元素,但我想这并不重要
<LinearLayout android:id="@+id/block1"
android:layout_width="fill_parent"
android:paddingLeft = "4sp"
android:padding = "4sp"
android:layout_height="25sp"
android:layout_marginTop = "4sp"
android:layout_below="@+id/Settings_phoneNumbersLbl"
android:orientation="horizontal">
<TextView android:id="@+id/Settings_phoneNumbersT1"
android:textColor="#000000"
android:textSize="14sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Settings_phoneNumbersT1"
/>
<EditText android:id="@+id/myRightAlignedText"
android:layout_width="170sp"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_alignParentRight = "true"
android:layout_gravity="right"
/>
</LinearLayout>
试试看
这与
android:layout_gravity="right"
前者影响内容在视图中的定位,即文本。后者会影响视图在其父视图中的位置。请参阅以获取完整的解释
编辑
要将
EditText
与其父项右侧对齐,请尝试将父项更改为RelativeLayout
而不是LinearLayout
,以便layout\u alignParentRight
属性可以生效。尝试使用RelativeLayout而不是LinearLayout
<RelativeLayout android:id="@+id/block1"
android:layout_width="fill_parent"
android:paddingLeft = "4sp"
android:padding = "4sp"
android:layout_height="25sp"
android:layout_marginTop = "4sp"
android:layout_below="@+id/Settings_phoneNumbersLbl"
android:orientation="horizontal">
<TextView android:id="@+id/Settings_phoneNumbersT1"
android:textColor="#000000"
android:textSize="14sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Settings_phoneNumbersT1"
/>
<EditText android:id="@+id/myRightAlignedText"
android:layout_width="170sp"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_alignParentRight = "true"
android:layout_gravity="right"
/>
</RelativeLayout>
根据LinearLayout属性,子元素始终对齐一个
一个接一个地水平或垂直移动
如果您想将子元素放在父元素的右侧,那么我认为您应该使用FrameLayout
或者只需使用RelativeLayout
,将两个子项按照相互尊重的方式放置
谢谢 您应该使用
android:layout_gravity="right"
因为
android:gravity ="right"
表示将视图的子项(此处为EditText-表示文本对齐)设置为右对齐。要对齐编辑文本本身,请使用第一个。我应该提到它。。。这将右对齐EditText中的文本,但我需要右对齐整个框。您使用的是水平方向。一个接一个地追加子视图。因此,我建议您使用RelativeLayout和layout\u alignParentRight,这样会有效。或者在中间加上一个空的视图,有一个权重。你想把EdvestTror对齐到右边,或者将EdEdTeX的内容对齐到右边……但是,编辑文本的高度缩小了。因此,我必须将高度设置为固定大小-包裹内容将使其非常薄…您将高度设置为RelativeLayout,只需将包裹内容/填充父项设置为高度,而不是固定大小
android:gravity ="right"