【问题标题】:How to add both horizontal and vertical view in a single activity.如何在单个活动中添加水平和垂直视图。
【发布时间】:2014-04-04 19:31:28
【问题描述】:

我想在一个活动中添加水平和垂直滚动。但我不能同时添加。我有一些例子。但是我的应用程序崩溃并强制关闭。

我已经关注了这个链接。

Link1 Link

我的要求是:-

顶部是水平滚动,底部是垂直滚动。

我尝试过这样的:-

    <HorizontalScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

            <ImageButton
                android:id="@+id/imageButton1"
                android:layout_width="70dp"
                android:layout_height="70dp"
                android:src="@android:drawable/btn_star" />

            <ImageButton
                android:id="@+id/imageButton2"
                android:layout_width="70dp"
                android:layout_height="70dp"
                android:src="@android:drawable/btn_star" />

        </LinearLayout>
    </HorizontalScrollView>

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

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        >
   <TextView android:id ="@+id/labelA"
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content"
   android:text="Name:"
   android:layout_x="0px"
   android:layout_y="5px"
/>

<EditText android:id="@+id/edtInput"
   android:layout_x="0px"
      android:layout_y="40px"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
/>

<TextView android:id ="@+id/labelB"
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content"
   android:text="Email:"
   android:layout_x="0px"
   android:layout_y="110px"
/>

<EditText android:id="@+id/edtInputA"
   android:layout_x="0px"
      android:layout_y="150px"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
/>

<Button android:id ="@+id/btnClick"
   android:layout_width="180px"
   android:layout_height="70px"
   android:text="Open New Screen"
   android:textSize="14px"
   android:layout_x="0px"
      android:layout_y="235px"
/>



    </LinearLayout>    
</ScrollView>

</LinearLayout>

请让我知道实现这一目标的任何想法。 提前致谢。

【问题讨论】:

    标签: android scroll


    【解决方案1】:

    我不明白这个问题。也许这可能有助于实现它,您应该将所有内容放入RelativeLayout并添加其属性如下:

    <RelativeLayout 
         ... >
    
         <HorizontalScrollView
             android:id="@+id/header"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_alignParentTop="true" >  
             <LinearLayout
                 android:layout_width="wrap_content"
                 android:layout_height="fill_parent" >
                 <!-- other views -->
             </LinearLayout>
         </HorizontalScrollView>
    
         <ScrollView
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_below="@id/header" >
             <LinearLayout
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content" >
                 <!-- other views -->
             </LinearLayout>
         </ScrollView>
    
    </RelativeLayout>  
    

    如果这有帮助,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-04
      • 2019-04-05
      • 2020-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多