gpt4 book ai didi

Android ScrollView 不滚动

转载 作者:行者123 更新时间:2023-11-29 21:46:24 25 4
gpt4 key购买 nike

我的布局里面有一个 ScrollView :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#eeeeee">

<!-- HEADER -->

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ffffff"
android:orientation="vertical" >
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#868686"
android:orientation="vertical" >
</LinearLayout>

<RelativeLayout
android:id="@+id/parent_linear"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/gradient_header" >

<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_marginBottom="@dimen/margin_normal"
android:layout_marginTop="@dimen/margin_small"
android:gravity="center_horizontal"
android:text="@string/proposed_plan_prompt"
android:textColor="#797A77"
android:textSize="15sp"
android:textStyle="bold" />

</RelativeLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#C7C7C7"
android:orientation="vertical" >
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@drawable/gradient_header_separator"
android:orientation="vertical" >
</LinearLayout>

</LinearLayout>

<!-- BODY -->

<!-- Proposed plan (summary) -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_normal"
android:layout_marginLeft="@dimen/margin_normal"
android:layout_marginRight="@dimen/margin_normal"
android:background="@drawable/border"
android:orientation="horizontal" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="@dimen/margin_small"
android:layout_marginRight="@dimen/margin_small"
android:orientation="vertical" >

<TextView
android:id="@+id/providerNameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="ABCD"
android:textSize="25sp"
android:textStyle="bold" />

<TextView
android:id="@+id/planView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="1234"
android:textSize="12sp"
android:textColor="#737373"/>

</LinearLayout>

<View
android:id="@+id/separator"
android:layout_width="1dip"
android:layout_height="50dp"
android:layout_marginTop="@dimen/margin_small"
android:background="@drawable/gradient_vertical" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_alignParentRight="true"
android:layout_marginLeft="@dimen/margin_small"
android:layout_marginRight="@dimen/margin_small"
android:orientation="vertical" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginLeft="@dimen/margin_small"
android:layout_marginRight="@dimen/margin_small"
android:gravity="top"
android:orientation="horizontal" >

<TextView
android:id="@+id/priceView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="XY"
android:textSize="32sp"
android:textStyle="bold" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="+123"
android:textColor="#565756"
android:textSize="12sp" />

</LinearLayout>

<TextView
android:id="@+id/totPriceView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="(information)"
android:textColor="#737373"
android:textSize="12sp" />

</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_normal"
android:layout_marginLeft="@dimen/margin_normal"
android:layout_marginRight="@dimen/margin_small"
android:layout_marginTop="@dimen/margin_normal"
android:orientation="vertical" >

<TextView
android:id="@+id/detailsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Choose:"
android:textSize="12sp"
android:textStyle="bold" />

<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />

<TextView
android:id="@+id/detailsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_small"
android:text="Best"
android:textColor="#737373"
android:textSize="12sp" />
</LinearLayout>

<TextView
android:id="@+id/detailsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_normal"
android:text="Details:"
android:textSize="12sp"
android:textStyle="bold" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_normal"
android:layout_marginLeft="@dimen/margin_normal"
android:layout_marginRight="@dimen/margin_small"
android:layout_marginTop="@dimen/margin_small"
android:background="@drawable/border"
android:orientation="vertical" >

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginLeft="90dp"
android:layout_marginRight="@dimen/margin_small"
android:background="@drawable/border"
android:orientation="vertical" >

<RelativeLayout
android:id="@+id/line1Layout"
android:layout_width="match_parent"
android:layout_height="30sp"
android:background="#ffffff"
android:gravity="center_vertical"
android:orientation="horizontal" >

<TextView
android:id="@+id/line1Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/font_normal" />

<TextView
android:id="@+id/line1Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/border_attribute"
android:textSize="@dimen/font_normal"
android:visibility="invisible" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/line2Layout"
android:layout_width="match_parent"
android:layout_height="30sp"
android:background="#EAEAEA"
android:gravity="center_vertical"
android:orientation="horizontal" >

<TextView
android:id="@+id/line2Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/font_normal" />

<TextView
android:id="@+id/line2Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/border_attribute"
android:textSize="@dimen/font_normal"
android:visibility="invisible" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/line3Layout"
android:layout_width="match_parent"
android:layout_height="30sp"
android:background="#ffffff"
android:gravity="center_vertical"
android:orientation="horizontal" >

<TextView
android:id="@+id/line3Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/font_normal" />

<TextView
android:id="@+id/line3Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/border_attribute"
android:textSize="@dimen/font_normal"
android:visibility="invisible" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/line4Layout"
android:layout_width="match_parent"
android:layout_height="30sp"
android:background="#EAEAEA"
android:gravity="center_vertical"
android:orientation="horizontal" >

<TextView
android:id="@+id/line4Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/font_normal" />

<TextView
android:id="@+id/line4Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/border_attribute"
android:textSize="@dimen/font_normal"
android:visibility="invisible" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/line5Layout"
android:layout_width="match_parent"
android:layout_height="30sp"
android:background="#ffffff"
android:gravity="center_vertical"
android:orientation="horizontal" >

<TextView
android:id="@+id/line5Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/font_normal" />

<TextView
android:id="@+id/line5Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/border_attribute"
android:textSize="@dimen/font_normal"
android:visibility="invisible" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/line6Layout"
android:layout_width="match_parent"
android:layout_height="30sp"
android:background="#EAEAEA"
android:gravity="center_vertical"
android:orientation="horizontal" >

<TextView
android:id="@+id/line6Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/font_normal" />

<TextView
android:id="@+id/line6Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/border_attribute"
android:textSize="@dimen/font_normal"
android:visibility="invisible" />
</RelativeLayout>
</LinearLayout>
</ScrollView>

<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="140dp"
android:layout_gravity="left|center_vertical"
android:src="@drawable/robin4" />
</FrameLayout>

<Button
android:id="@+id/button_proposed_extras"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_small"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="@dimen/margin_normal"
android:background="@drawable/button_transparent"
android:text="@string/extras_title"
android:textColor="#298A17"
android:textStyle="bold|italic"
android:visibility="invisible" />
</LinearLayout>

<Button
android:id="@+id/button_proposed_change"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_normal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/button"
android:text="@string/proposition_change_title"
android:textColor="#ffffff"
android:textStyle="bold" />

<Button
android:id="@+id/button_proposed_no_change"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_normal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/button_silver"
android:text="@string/proposition_no_change_title"
android:textColor="#298A17"
android:textStyle="bold" />


</LinearLayout>
  • 带有 ScrollView 的部分以最大尺寸显示并且不滚动。

  • 末尾的两个按钮没有显示,它们显然不适合屏幕。

我想让滚动条正常工作,以便显示按钮。

为什么滚动的布局显示为最大尺寸而不是滚动?

解决方案是什么?

最佳答案

为了让按钮出现在屏幕上,你也应该让按钮在滚动条中。大多数情况下,如果屏幕包含许多组件,您设计的屏幕应该将 ScrollView 作为父级。 Main ScrollView -> LinearLayout/RelativeLayout -> 根据需要添加组件。通过这样做,您应该也能够看到按钮。通过这种方式,即使您的布局更改为横向,组件也不会被隐藏并显示在滚动中。希望您明白我的意思,它可以帮助您解决问题。

就上面的代码而言,您将看不到按钮,因为按钮不在 ScrollView 中,因此下面的 View 被隐藏。

关于Android ScrollView 不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15693941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com