[英]Listview Item layout pushes the linearlayout off the screen
I am new to android and am trying to create a list view row item as follows: 我是android的新手,我正在尝试创建列表视图行项,如下所示:
I want to make the width of the center textviews a constant size, irrespective to the length of text. 我想使中心文本视图的宽度不变,与文本的长度无关。
Every time I adjust the middle linear layout, it pushes the checkbox off the screen unless I manually give it a width (which will not work for multiple screen sizes). 每当我调整中间线性布局时,它都会将复选框从屏幕上推开,除非我手动给它一个宽度(这对多个屏幕尺寸不起作用)。 Can someone please help? 有人可以帮忙吗?
I've tried using weights and all but I can't figure it out. 我尝试过使用砝码,但我无法弄明白。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="left"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/starttime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:singleLine="true"
android:text="10:35am"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#929692"
android:textSize="12sp" />
<TextView
android:id="@+id/endtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:singleLine="true"
android:text="11:55am"
android:textColor="#929692"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/middle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_toRightOf="@id/left"
android:orientation="vertical">
<TextView
android:id="@+id/sessionname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:padding="2dp"
android:singleLine="true"
android:text="ok this is where my text goes it is very long
and it will push stuff off"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textSize="14sp" />
<TextView
android:id="@+id/location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:ellipsize="end"
android:singleLine="true"
android:text="@android:string/ok"
android:textColor="#929692" />
</LinearLayout>
<LinearLayout
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_toRightOf="@id/middle"
android:orientation="vertical">
<CheckBox
android:id="@+id/list_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:checked="false" />
</LinearLayout>
</RelativeLayout>
使用了constraintlayout并且它工作了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.