gpt4 book ai didi

android - 无法将 scrollView 添加到布局

转载 作者:行者123 更新时间:2023-11-29 01:39:02 24 4
gpt4 key购买 nike

我必须将我的布局分成两部分:

  1. 上部应没有 ScrollView (为了绘制水平和垂直线。我在绘制垂直线时遇到了问题,当完整的布局有一个 ScrollView 时)
  2. 下部应带有ScrollView(以便滚动浏览不同的元素)

这张图片应该解释它应该是什么样子: enter image description here

我的布局文件看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawingLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical" >

<com.unitnode.Drawing
android:id="@+id/drawingView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<ImageButton
android:id="@+id/eraseButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rubber" />

<ImageButton
android:id="@+id/undoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/undo" />

<ImageButton
android:id="@+id/neuerZeichenButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/newbutton" />

<ImageButton
android:id="@+id/saveZeichenView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/savebutton" />

<View
android:id="@+id/linie1"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />

<TextView
android:id="@+id/hintergrundfarbeFullZeichenView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hintergrundfarbe" />

<Button
android:id="@+id/hintergrundfarbeFullButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/schwarzbuttonshape" />

<Button
android:id="@+id/hintergrundfarbeFullButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/roterbuttonshape" />

<Button
android:id="@+id/hintergrundfarbeFullButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/gelberbuttonshape" />

<Button
android:id="@+id/hintergrundfarbeFullButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/weiserbuttonshape" />

<ImageButton
android:id="@+id/hintergrundfarbeFullButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/farbpallete" />

<View
android:id="@+id/linie2"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />

<TextView
android:id="@+id/strichfarbeFullText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Strichfarbe" />

<Button
android:id="@+id/strichfarbeFullButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/schwarzbuttonshape" />

<Button
android:id="@+id/strichfarbeFullButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/roterbuttonshape" />

<Button
android:id="@+id/strichfarbeFullButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/gelberbuttonshape" />

<Button
android:id="@+id/strichfarbeFullButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/weiserbuttonshape" />

<ImageButton
android:id="@+id/strichfarbeFullButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/farbpallete" />

<View
android:id="@+id/linie3"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />

<TextView
android:id="@+id/strichdickeTextFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Strichdicke" />

<SeekBar
android:id="@+id/strokeSeekbarFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/strichdickeTextMinFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0dp" />

<View
android:id="@+id/linie4"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />

<TextView
android:id="@+id/opacityText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Durchsichtigkeit: " />

<TextView
android:id="@+id/opacityMinText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0% " />

<SeekBar
android:id="@+id/opacitySeekbarFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<CheckBox
android:id="@+id/unschaerfeFilterCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unschärfefilter AN/AUS"
android:textSize="12sp" />

<TextView
android:id="@+id/radiusTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radius:" />

<TextView
android:id="@+id/radiusMinTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1dp" />

<SeekBar
android:id="@+id/unschaerfeSeekbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<RadioButton
android:id="@+id/unschaerfeCheckBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Inner"
android:textSize="10sp" />

<RadioButton
android:id="@+id/unschaerfeCheckBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal"
android:textSize="10sp" />

<RadioButton
android:id="@+id/unschaerfeCheckBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Outer"
android:textSize="10sp" />

<RadioButton
android:id="@+id/unschaerfeCheckBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Solid"
android:textSize="10sp" />

<TextView
android:id="@+id/formenText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Formen: " />

<ImageButton
android:id="@+id/kreisFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/kreis" />

元素 com.unitnode.Drawing 是我的绘图 View (上半部分)。

我尝试了不同的方法但没有成功:

  1. 在整个页面上定义了 1 个 ScrollView 并试图限制它的高度 -> 无法绘制垂直线
  2. layout_height 更改为 wrap_content -> 没有变化。我也将它定义为 com.unitnode.Drawing,但是由于 onSizeChanged( ) 方法(宽度和高度必须 > 0),应用程序关闭了
  3. 我试图在绘图 View 之后插入一个 ScrollView 元素。并为此添加了另一个 Framelayout -> 无法处理

如果您需要 Java 代码,请告诉我。

请帮我更改代码,使布局由两部分组成(如图所示)

编辑:我将我的 xml 文件更改为此(使用 FrameLayout 因为格式正确):

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawingLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >

<FrameLayout
android:id="@+id/drawingLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<com.unitnode.Drawing
android:id="@+id/drawingView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>

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

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

<ImageButton
android:id="@+id/eraseButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rubber" />

<ImageButton
android:id="@+id/undoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/undo" />

<ImageButton
android:id="@+id/neuerZeichenButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/newbutton" />

<ImageButton
android:id="@+id/saveZeichenView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/savebutton" />

<View
android:id="@+id/linie1"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />

<TextView
android:id="@+id/hintergrundfarbeFullZeichenView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hintergrundfarbe" />

<Button
android:id="@+id/hintergrundfarbeFullButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/schwarzbuttonshape" />

<Button
android:id="@+id/hintergrundfarbeFullButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/roterbuttonshape" />

<Button
android:id="@+id/hintergrundfarbeFullButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/gelberbuttonshape" />

<Button
android:id="@+id/hintergrundfarbeFullButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/weiserbuttonshape" />

<ImageButton
android:id="@+id/hintergrundfarbeFullButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/farbpallete" />

<View
android:id="@+id/linie2"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />

<TextView
android:id="@+id/strichfarbeFullText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Strichfarbe" />

<Button
android:id="@+id/strichfarbeFullButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/schwarzbuttonshape" />

<Button
android:id="@+id/strichfarbeFullButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/roterbuttonshape" />

<Button
android:id="@+id/strichfarbeFullButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/gelberbuttonshape" />

<Button
android:id="@+id/strichfarbeFullButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/weiserbuttonshape" />

<ImageButton
android:id="@+id/strichfarbeFullButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/farbpallete" />

<View
android:id="@+id/linie3"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />

<TextView
android:id="@+id/strichdickeTextFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Strichdicke" />

<SeekBar
android:id="@+id/strokeSeekbarFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/strichdickeTextMinFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0dp" />

<View
android:id="@+id/linie4"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000" />

<TextView
android:id="@+id/opacityText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Durchsichtigkeit: " />

<TextView
android:id="@+id/opacityMinText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0% " />

<SeekBar
android:id="@+id/opacitySeekbarFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<CheckBox
android:id="@+id/unschaerfeFilterCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unschärfefilter AN/AUS"
android:textSize="12sp" />

<TextView
android:id="@+id/radiusTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radius:" />

<TextView
android:id="@+id/radiusMinTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1dp" />

<SeekBar
android:id="@+id/unschaerfeSeekbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<RadioButton
android:id="@+id/unschaerfeCheckBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Inner"
android:textSize="10sp" />

<RadioButton
android:id="@+id/unschaerfeCheckBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal"
android:textSize="10sp" />

<RadioButton
android:id="@+id/unschaerfeCheckBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Outer"
android:textSize="10sp" />

<RadioButton
android:id="@+id/unschaerfeCheckBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Solid"
android:textSize="10sp" />

<TextView
android:id="@+id/formenText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Formen: " />

<ImageButton
android:id="@+id/kreisFull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/kreis" />
</FrameLayout>
</ScrollView>

</FrameLayout>

最佳答案

您应该尝试如下布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawingLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >

<RelativeLayout
android:id="@+id/drawingContainerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<!-- Need to add your drawing view-->
</RelativeLayout>

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<!-- Bottom views that are scrollable -->



</LinearLayout>
</ScrollView>

</LinearLayout>

关于android - 无法将 scrollView 添加到布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25974607/

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