相关疑难解决方法(0)

Android:为什么视图没有maxHeight?

View有一个minHeight但不知何故缺少一个maxHeight:

我想要实现的是让一些项目(视图)填满ScrollView.当有1..3项时,我想直接显示它们.意味着它ScrollView具有1,2或3个项目的高度.

当有4个或更多项目我希望ScrollView停止扩展(因此a maxHeight)并开始提供滚动.

但是,遗憾的是没有办法设置maxHeight.因此,我可能必须以ScrollView编程方式WRAP_CONTENT将高度设置为有1..3项3*sizeOf(View)时的高度,并将高度设置为有4个或更多项时的高度.

任何人都可以解释为什么没有maxHeight提供,什么时候已经有minHeight

(顺便说一下:有些观点,比如ImageView已经maxHeight实施了.)

layout android view autoresize

168
推荐指数
7
解决办法
11万
查看次数

ScrollView中的ListView不在Android上滚动

我在滚动ListView里面遇到麻烦ScrollView.我有一个Activity在顶部有一些EditTexts,然后是一个带有两个选项卡的选项卡主机,每个选项卡都有一个ListView.当EditText视图聚焦时,软键盘出现,因为我有一个ScrollView,内容是可滚动的.但问题出现在ListViews中有更多项目(选项卡中的项目),即使有更多项目,我也无法滚动ListView.

以下是布局XML:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="?backgroundImage"
    android:orientation="vertical">

  <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:layout_alignParentBottom="true"
        android:layout_margin="10dip"
        android:id="@+id/buttons">
    <Button
            android:text="Save"
            android:layout_margin="2dip"
            android:textSize="20dip"
            android:id="@+id/btnSaveorUpdate"
            android:layout_height="wrap_content"
            android:layout_width="145dip"></Button>
    <Button
            android:text="Cancel"
            android:layout_margin="2dip"
            android:textSize="20dip"
            android:id="@+id/btnCancelorDelete"
            android:layout_height="wrap_content"
            android:layout_width="145dip"></Button>
  </LinearLayout>
  <ScrollView
        android:layout_above="@id/buttons"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        android:layout_margin="10dip">
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="10dip">
      <TextView
                android:text="Bill details"
                android:textColor="?textColorDark"
                android:layout_alignParentTop="true"
                android:id="@+id/txtEnterDetails"
                android:textSize="25dip"
                android:textStyle="bold"
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:layout_marginBottom="2dip"></TextView>
      <LinearLayout
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:layout_width="0dip"
                android:layout_height="0dip" />
      <EditText
                android:layout_width="fill_parent"
                android:hint="Enter data"
                android:inputType="numberDecimal"
                android:id="@+id/txtSample"
                android:textSize="@dimen/editText"
                android:layout_height="@dimen/editTextHeight"
                android:text=""></EditText>
      <EditText
                android:layout_width="fill_parent"
                android:id="@+id/txtDescription"
                android:hint="Enter description"
                android:textSize="@dimen/editText" …
Run Code Online (Sandbox Code Playgroud)

android listview scrollview android-layout

151
推荐指数
9
解决办法
20万
查看次数

如何设置RecyclerView Max Height

我想设置RecylerView的Max Height.我可以使用下面的代码设置最大高度.下面的代码使高度为当前屏幕的60%.

     DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int a = (displaymetrics.heightPixels * 60) / 100;
    recyclerview1.getLayoutParams().height = a;
Run Code Online (Sandbox Code Playgroud)

但现在的问题是,如果它没有项目,那么它的高度也是60%.所以我想在没有项目时将其高度设置为0.

我希望实现类似的东西.

    if(recyclerview's height > maxHeight)
then set recyclerview's height to maxHeight
    else dont change the height of recyclerview.
Run Code Online (Sandbox Code Playgroud)

我怎么设置它?请帮助我,我坚持下去

android android-recyclerview

21
推荐指数
5
解决办法
2万
查看次数