【发布时间】:2013-12-05 03:47:35
【问题描述】:
我尝试用滚动视图包装我的 relativelayout 以在横向模式下使用,但它不起作用。我也尝试用线性布局包裹我的相对布局,但它也不起作用。
这是将 relativelayout 包裹在滚动视图中的 xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2d89ef">
<!--Some components here-->
</RelativeLayout>
</ScrollView>
这是我的完整 xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2d89ef">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="Segoe UI Light"
android:gravity="center"
android:text="@string/app_name"
android:textColor="#FFFFFF"
android:textSize="25dp"
android:textIsSelectable="false"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp" />
<EditText
android:id="@+id/editText"
android:layout_width="275dp"
android:layout_height="wrap_content"
android:ems="10"
android:fontFamily="Segoe UI Light"
android:gravity="center_vertical"
android:hint="@string/username"
android:inputType="textPersonName"
android:textColor="@android:color/white"
android:textSize="16sp"
android:width="200dp"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true">
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:ems="10"
android:fontFamily="Segoe UI Light"
android:gravity="center_vertical"
android:hint="@string/password"
android:inputType="textPassword"
android:textColor="@android:color/white"
android:textSize="16sp"
android:width="200dp"
android:layout_below="@+id/editText"
android:layout_alignRight="@+id/editText"
android:layout_alignLeft="@+id/editText" />
<Button
android:id="@+id/button"
android:layout_width="250dp"
android:layout_height="40dp"
android:background="@drawable/border"
android:fontFamily="Segoe UI Light"
android:height="20dp"
android:text="@string/login"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:width="200dp"
android:layout_marginTop="25dp"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_alignRight="@+id/editText2" />
<Button
android:id="@id/btnForgot"
android:layout_width="250dp"
android:layout_height="40dp"
android:background="@drawable/border"
android:fontFamily="Segoe UI Light"
android:height="20dp"
android:text="@string/forgot_password"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:width="200dp"
android:layout_below="@+id/button"
android:layout_alignLeft="@+id/button"
android:layout_alignRight="@+id/button" />
<ImageView
android:layout_width="140dp"
android:layout_height="200dp"
android:id="@+id/imageView"
android:background="@drawable/auf_logo"
android:layout_above="@+id/textView"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</ScrollView>
【问题讨论】:
-
您添加的内容是否足以滚动?
-
是的,当我进入横向模式时,我看不到一些按钮,所以我试图用滚动视图来结束它
-
为滚动视图中的内容做一个wrapcontent..它可能对你有用
-
pastie.org/8529914 试试这个代码让我知道它是否对你有帮助?它对我有用
-
请检查我的答案..我已根据您的 xml 文件更改它..
标签: android android-layout scrollview