Android 如何阻止EditText在RelativeLayout中占据整个宽度
我有下面的布局,基本上显示“消息”作为泡沫更粘内置的“消息”。我只需要在右侧显示一个箭头图像,该图像已显示,但问题是: 当Android 如何阻止EditText在RelativeLayout中占据整个宽度,android,Android,我有下面的布局,基本上显示“消息”作为泡沫更粘内置的“消息”。我只需要在右侧显示一个箭头图像,该图像已显示,但问题是: 当“EditText”有大量文本时,它会占用整个宽度,图像视图仍会显示,但会显示在“EditText的顶部 如何阻止“EditText”占据整个宽度,我尝试了android:layou-weight,但没有成功 有线索吗 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="ht
“EditText”
有大量文本时,它会占用整个宽度,图像视图
仍会显示,但会显示在“EditText
的顶部
如何阻止“EditText”占据整个宽度,我尝试了android:layou-weight
,但没有成功
有线索吗
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<!-- android:background="#FFDBE2ED"-->
<LinearLayout
android:id="@+id/wrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00DBE2ED"
>
<RelativeLayout
android:id="@+id/wrapper2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00DBE2ED"
android:weightSum="1.0"
>
<!-- android:layout_gravity="center" -->
<EditText
android:id="@+id/comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:editable="false"
android:layout_marginTop="5dip"
android:layout_marginRight="5dip"
android:layout_marginLeft="5dip"
android:background="@drawable/bubble_yellow"
android:paddingLeft="10dip"
android:text="Hello bubbles!"
android:textColor="@android:color/primary_text_light"
android:layout_weight=".70"
/>
<TextView
android:id="@+id/sender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dip"
android:paddingLeft="5dip"
android:paddingRight="2dip"
android:text="Hello bubbles!"
android:textColor="#b9dcdcdc"
android:textSize="11sp"
android:layout_below="@+id/comment"
/>
<ImageView
android:id="@+id/aquaplayicon"
android:src="@drawable/aquaplayicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="onClickGirl"
android:layout_alignParentRight="true"
android:paddingRight="5dip"
android:layout_centerVertical="true"
android:layout_weight=".30"
/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
将EditText设置为一些预定义的大小: 说
android:layout_width=“80dp”将EditText设置为一些预定义的大小: 说
android:layout_width=“80dp”在
EditText
并在编辑文本中使用android:layout_toLeftOf=“@id/aquaplaycon”
而layout\u-weight
不适用于RelativeLayout
编辑:试试这个
<LinearLayout
android:id="@+id/wrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00DBE2ED"
android:orientation="vertical"
>
<LinearLayout
android:id="@+id/wrapper2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00DBE2ED"
android:weightSum="1.0"
android:orientation="horizontal"
>
<!-- android:layout_gravity="center" -->
<EditText
android:id="@+id/comment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"
android:layout_marginTop="5dip"
android:layout_marginRight="5dip"
android:layout_marginLeft="5dip"
android:background="@drawable/bubble_yellow"
android:paddingLeft="10dip"
android:text="Hello bubbles!"
android:textColor="@android:color/primary_text_light"
android:layout_weight="1"
/>
<ImageView
android:id="@+id/aquaplayicon"
android:src="@drawable/aquaplayicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="onClickGirl"
android:paddingRight="5dip"
android:layout_centerVertical="true"
/>
</LinearLayout>
<TextView
android:id="@+id/sender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dip"
android:paddingLeft="5dip"
android:paddingRight="2dip"
android:text="Hello bubbles!"
android:textColor="#b9dcdcdc"
android:textSize="11sp"
android:layout_below="@+id/comment"
/>
</LinearLayout>
在
EditText
并在编辑文本中使用android:layout_toLeftOf=“@id/aquaplaycon”
而layout\u-weight
不适用于RelativeLayout
编辑:试试这个
<LinearLayout
android:id="@+id/wrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00DBE2ED"
android:orientation="vertical"
>
<LinearLayout
android:id="@+id/wrapper2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00DBE2ED"
android:weightSum="1.0"
android:orientation="horizontal"
>
<!-- android:layout_gravity="center" -->
<EditText
android:id="@+id/comment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"
android:layout_marginTop="5dip"
android:layout_marginRight="5dip"
android:layout_marginLeft="5dip"
android:background="@drawable/bubble_yellow"
android:paddingLeft="10dip"
android:text="Hello bubbles!"
android:textColor="@android:color/primary_text_light"
android:layout_weight="1"
/>
<ImageView
android:id="@+id/aquaplayicon"
android:src="@drawable/aquaplayicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="onClickGirl"
android:paddingRight="5dip"
android:layout_centerVertical="true"
/>
</LinearLayout>
<TextView
android:id="@+id/sender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dip"
android:paddingLeft="5dip"
android:paddingRight="2dip"
android:text="Hello bubbles!"
android:textColor="#b9dcdcdc"
android:textSize="11sp"
android:layout_below="@+id/comment"
/>
</LinearLayout>
我会尝试将您的相对布局更改为水平方向的线性布局
,并从左到右添加元素。然后你可以使用android:layout\u weight来确保所有内容都显示在屏幕上。我会尝试将你的相对布局更改为水平方向的线性布局
,并从左到右添加元素。然后,您可以使用android:layout\u weight确保所有内容都显示在屏幕上。为线性布局中的组件指定布局权重,并设置android:layout\u width=“0dip”为线性布局中的组件指定布局权重,并设置android:layout\u width=“0dip”如果您正在使用一些后台资源,并且希望您的EditText大小保持不变,然后设置为可绘制
andrid:maxEms="5"; // You can use any small value,
其他明智的使用
andrid:maxEms // For Max width with respect to number of character (Text)
android:maxWidth // For max with in dp
如果您正在使用一些后台资源,并且希望EditText大小保持不变,并且可绘制,则设置
andrid:maxEms="5"; // You can use any small value,
其他明智的使用
andrid:maxEms // For Max width with respect to number of character (Text)
android:maxWidth // For max with in dp
尝试将android:layout\u width=“fill\u parent”更改为android:layout\u width=“wrap\u content”尝试将android:layout\u width=“fill\u parent”更改为android:layou width=“wrap\u content”使用不同屏幕大小/分辨率时,使用固定宽度可能会出现问题。根据屏幕大小动态设置宽度很好。使用不同的屏幕大小/分辨率时,使用固定宽度可能会出现问题。根据屏幕大小动态设置宽度很好。我尝试过,但当EditText中有大量文本时,它仍然没有阻止EditText占用整个空间。我尝试过,但当EditText中有大量文本时,它仍然没有阻止EditText占用整个空间。