[英]How to scroll horizontally and vertically this layout
i am trying to scroll down this main layout horizontally and vertically , if this main layout does not fit into the user phone while the user holding the phone vertically or horizontally, he has the option scroll it. 我试图水平和垂直向下滚动此主布局,如果在用户垂直或水平握住电话的同时该主布局不适合用户手机,则可以选择滚动。 thanks
谢谢
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/description"
android:lines="4"
android:gravity="center"
android:textColor="@color/text"
android:background="@drawable/text_background"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/lgn"
android:lines="2"
android:textColor="@color/text"
android:gravity="center" />
<Button
android:id="@+id/click_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textStyle="bold"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/rgs"
android:textColor="@color/text"
android:lines="2"
android:gravity="center"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="6"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="1dip"
android:lines="10"
android:background="#8B8989"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/foter"
android:lines="2"
android:gravity="center"
android:textColor="@color/Blue"
/>
</LinearLayout>
I edited your xml code as below: 我编辑了您的xml代码,如下所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scro1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_x="***dp"
android:layout_y="***dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="***dp"
android:layout_y="***dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/description"
android:lines="4"
android:gravity="center"
android:textColor="@color/text"
android:background="@drawable/text_background"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/lgn"
android:lines="2"
android:textColor="@color/text"
android:gravity="center" />
<Button
android:id="@+id/click_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textStyle="bold"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/rgs"
android:textColor="@color/text"
android:lines="2"
android:gravity="center"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="6"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="1dip"
android:lines="10"
android:background="#8B8989"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/foter"
android:lines="2"
android:gravity="center"
android:textColor="@color/Blue"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
***dp represents from where you want to scroll the LinearLayout
. *** dp表示要从其中滚动
LinearLayout
。
did you try putting everything inside a "ScrollView"? 您是否尝试将所有内容都放入“ ScrollView”中? :-)
:-)
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout>
<!-- Your linear layout here -->
</LinearLayout>
</ScrollView>
Cheers! 干杯!
You can use below coding. 您可以使用以下编码。
Vertical scrolling: 垂直滚动:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
// all views to scroll
</LinearLayout>
</ScrollView>
horizontal scrolling: 水平滚动:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
// all views to scroll
</LinearLayout>
</HorizontalScrollView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.