无法将scrollView添加到布局中

时间:2014-09-22 12:49:49

标签: android android-layout canvas uiscrollview

我必须将布局分为两部分:

  1. 上部应该是没有ScrollView (为了绘制水平和垂直线。当完整的布局有ScrollView时,我有绘制垂直线的问题)
  2. 下部应为,使用ScrollView (为了滚动浏览不同的元素)
  3. 这张照片应该说明它应该是什么样的: 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是我的绘图视图(上半部分)。

    我尝试了不同的事情但没有成功:

    1. 在整页上定义了1 ScrollView并试图限制它的高度 - &gt; 不能绘制垂直线
    2. layout_height更改为wrap_content - &gt; 无变化。我将其定义为com.unitnode.Drawing,但由于onSizeChanged( )方法(宽度和高度必须> 0),应用关闭了
    3. 我尝试在绘图视图后插入ScrollView元素。并添加了另一个Framelayout - &gt;无法处理
    4. 如果您需要Java代码,请告诉我。

      请帮我改变我的代码,以便布局由两部分组成(如图所示)

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

      &#13;
      &#13;
      <?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>
      &#13;
      &#13;
      &#13;

2 个答案:

答案 0 :(得分:1)

您应该尝试如下布局:

<?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>

答案 1 :(得分:0)

看来,ScrollView位于整个底层FrameLayout的顶部。这就是原因,因为我无法画任何东西。当我将ScrollView的Visibilty设置为invisible而不是我能够再次绘制时。但我无法肯定地看到这些元素。

除了改变可见度之外还有其他方法吗?是否有可能将底层的FrameLayout带到前面,我怎么能实现呢?

相关问题