【发布时间】:2019-01-05 13:41:24
【问题描述】:
这是我面临的问题的代码,我在滚动视图中采用了 2 个线性布局,现在第 2 个线性布局内的最后一个按钮被隐藏,或者我可以说没有正确显示。
这是屏幕截图。 您可以检查我选择的区域是按钮但不能正常工作。
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:id="@+id/ConcernedPortionofScreen"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/RestofScreen"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.75"
android:orientation="vertical"
android:padding="20dp">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/custom_button_shape_with_bg_primary"
android:minHeight="@dimen/minimum_height_all_object"
android:layout_marginTop="@dimen/add_child_rquest_margin_top"
android:text="SELECT"
android:textColor="@color/white"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
当我尝试删除 layout_weight 时,我的布局变得越来越重。
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical"
tools:context=".MainActivity">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:id="@+id/ConcernedPortionofScreen"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:orientation="vertical">
<!-- Parent FrameLayout 'FL' -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Conitans Tree Childs -->
</FrameLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/RestofScreen"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.75"
android:orientation="vertical"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<!--Conitans Two Childs -->
</LinearLayout>
<EditText
style="@style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/add_child_rquest_margin_top"
android:hint="Enter Child Name"
android:minHeight="@dimen/add_child_rquest_minimum_height_all_object" />
<EditText
style="@style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/add_child_rquest_margin_top"
android:hint="Select City"
android:minHeight="@dimen/add_child_rquest_minimum_height_all_object" />
<TextView
style="@style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/add_child_rquest_margin_top"
android:hint="Select Birthdate"
android:minHeight="@dimen/add_child_rquest_minimum_height_all_object" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<!--Conitans Two Childs -->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<!--Conitans Two Childs -->
</LinearLayout>
<EditText
style="@style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/add_child_rquest_margin_top"
android:hint="Enter Mobile Number"
android:minHeight="@dimen/add_child_rquest_minimum_height_all_object" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<!--Conitans Two Childs -->
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/add_child_rquest_margin_top"
android:fontFamily="@font/segoe_ui_bold"
android:paddingLeft="10dp"
android:text="Note / Message :"
android:textColor="@color/colorPrimaryDark"
android:textSize="18dp" />
<EditText
style="@style/CustomEdittextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/add_child_rquest_margin_top"
android:inputType="textMultiLine"
android:lines="8"
android:maxLines="8"
android:minHeight="@dimen/add_child_rquest_minimum_height_all_object"
android:minLines="8"
android:scrollbars="vertical" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/add_child_rquest_margin_top"
android:background="@drawable/custom_button_shape_with_bg_primary"
android:fontFamily="@font/segoe_ui_bold"
android:minHeight="@dimen/add_child_rquest_minimum_height_all_object"
android:text="SUBMIT"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
什么是android:minHeight=""尺寸值?
-
您将 LinearLayout 高度设置为
match_parent,因此永远不会滚动。 -
@SushilKumar 它的 ' android:minHeight="40dp" '
-
@dharms 滚动工作,上面有很多项目,但最后一个项目有问题。我对其他布局也有同样的问题。
-
你不应该在scrollview的子节点上使用匹配父节点并移除权重,这些是主要问题。
标签: android scrollview android-linearlayout android-scrollview