最近在项目中遇到了这个问题 :如下
<android.support.v4.widget.NestedScrollView android:id="@id/nsv_edit_again" android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout
android:id="@id/ll_edit_again" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<LinearLayout android:layout_weight="1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <CheckBox android:gravity="center" android:id="@id/cb_first_schedule" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:visibility="gone"/> <EditText android:layout_weight="1" android:textColorHint="@color/colorPrimary" android:hint="@string/note_edit_hint" android:textSize="20dp" android:paddingTop="10dp" android:id="@id/et_first_schedule" android:background="@null" android:paddingLeft="10dp" android:paddingRight="10dp" android:gravity="left|top" android:inputType="textMultiLine" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> </LinearLayout>
</android.support.v4.widget.NestedScrollView> 然后布局中LinearLayout高度会自动为wrap_parent,如下:
解决办法就是给NestedScrollView或ScrollView设置属性
android:fillViewport="true" 所以代码修改如下:
<android.support.v4.widget.NestedScrollView android:fillViewport="true" android:id="@id/nsv_edit_again" android:layout_width="match_parent" android:layout_height="match_parent"> ...
达到我们需要的结果: