我尝试在内部创建一个ListView
内部。所以我使用自定义方法来制作我的NonScrollable。ScrollView
EdiText
ListView
ListView
我的 ListView 项目 xml 是这样的:
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/title1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="3"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="3dp"
android:text="Text"
android:textColor="#222"
android:textSize="18sp"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/title2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_below="@+id/title1"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingBottom="2dp"
android:text="New Text"
android:textColor="#727272"
android:textSize="15sp"
tools:ignore="HardcodedText" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title2"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="8dp"
android:hint="Note"
android:textSize="13sp"
android:id="@+id/text_note"/>
</RelativeLayout>
自定义方法代码是这样的:
public class NonScrollListView extends ListView {
public NonScrollListView(Context context) {
super(context);
}
public NonScrollListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
}
问题是当我在 EditText 中创建一个新行时,我的列表视图高度没有调整,并使我在 ListView 中的最后一个项目消失。截图是这样的:
我从这里看到: Android: Listview in ScrollView with dynamic height
它说更改ListView
为LinearLayout
..有人可以帮我怎么做吗?我不知道如何更改ListView
为LinearLayout
.
如果不必更改,LinearLayout
有什么办法可以调整我的高度,ListView
这样我的物品就不会消失?
需要帮助来解决这个问题。