如何使线性布局水平滚动?我只是将线性布局包装在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>
最佳答案
检查此链接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>
关于android - 使线性布局水平滚动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12317648/