使线性布局可水平滚动

时间:2012-09-07 11:58:02

标签: android android-layout android-scrollview

如何使线性布局水平滚动?我只是在myscrollview中包装一个线性布局,我也在我的XML文件中做了所需的但是它仍然无法水平滚动超出线性布局大小的内容。这是我的XML:              

    <ScrollView 
        android:id="@+id/scroller"
        android:layout_marginTop="16dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/popup"
        android:fadingEdgeLength="5dip"
        android:scrollbars="horizontal"
        android:overScrollMode="always" 
        android:isScrollContainer="true" 
        android:scrollbarAlwaysDrawHorizontalTrack="true"
        >

        <LinearLayout
            android:id="@+id/tracks"
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:padding="10dip"/>

    </ScrollView >

    <ImageView
        android:id="@+id/arrow_up"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/arrow_up" />

    <ImageView
        android:id="@+id/arrow_down"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/scroller"
        android:layout_marginTop="-4dip"
        android:src="@drawable/arrow_down" />

</RelativeLayout>

3 个答案:

答案 0 :(得分:3)

答案 1 :(得分:2)

是否使用<HorizontalScrollView ></HorizontalScrollView>标记进行了尝试? 只需在

的地方尝试上面的标记即可

答案 2 :(得分:2)

点击此链接http://android.okhelp.cz/horizontalscrollview-scrollview-horizontal-vertical-android-xml-example/

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.ImageButton;

  public class HorizontalscroolActivity extends Activity {


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ImageButton btn11 = (ImageButton) findViewById(R.id.imageButton1);


    ImageButton btn2 = (ImageButton) findViewById(R.id.imageButton2);


    ImageButton btn3 = (ImageButton) findViewById(R.id.imageButton3);


    ImageButton btn4 = (ImageButton) findViewById(R.id.imageButton4);


}

  }

在XMLFILE中

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">
            <ImageButton
                android:id="@+id/imageButton1"
                android:layout_width="wrap_content"
                android:layout_height="100dp"
                android:src="@drawable/pic7"
                android:text="image1" />
            <TextView
                android:id="@+id/text"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Textview1" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:orientation="vertical"
            android:layout_height="fill_parent">
            <ImageButton
                android:text="image2"
                android:id="@+id/imageButton2"
                android:layout_width="wrap_content"
                android:layout_height="100dp"
                android:src="@drawable/pic2" />
            <TextView
                android:id="@+id/text"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Textview2" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:orientation="vertical"
            android:layout_height="fill_parent">
            <ImageButton
                android:text="image3"
                android:id="@+id/imageButton3"
                android:layout_width="wrap_content"
                android:layout_height="100dp"
                android:src="@drawable/pic7" />
            <TextView
                android:id="@+id/text"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Textview3" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:orientation="vertical"
            android:layout_height="fill_parent">
            <ImageButton
                android:text="image4"
                android:id="@+id/imageButton4"
                android:layout_width="wrap_content"
                android:layout_height="100dp"
                android:src="@drawable/pic5" />
            <TextView
                android:id="@+id/text4"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Textview4" />
        </LinearLayout>
    </LinearLayout>
</HorizontalScrollView>