Syl*_*nek 6 layout android scrollview relativelayout
我正在玩Android布局并尝试进行简单的QA测试,但我无法正确布局.我只是不知道如何调整这些东西,经过几个小时的战斗,我需要一些帮助.
这就是我想要的:

我得到了什么:

这是我的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<RelativeLayout
android:id="@+id/nodeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="TextView"
android:textSize="18dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/radioAnswersGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</RadioGroup>
<LinearLayout
android:id="@+id/questionsNavigationGroup"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<Button
android:id="@+id/buttonPreviousQuestion"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1"
android:background="@drawable/fancy_button"
android:gravity="center|center_vertical"
android:onClick="onPreviousQuestionButtonClick"
android:shadowColor="#fff"
android:shadowRadius="3"
android:text="Back"
android:textColor="#432f11"
android:textSize="24dp" />
<Button
android:id="@+id/buttonNextQuestion"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1"
android:background="@drawable/fancy_button"
android:gravity="center|center_vertical"
android:onClick="onNextQuestionButtonClick"
android:shadowColor="#fff"
android:shadowRadius="3"
android:text="Next"
android:textColor="#432f11"
android:textSize="24dp" />
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
答案和按钮应始终位于底部,问题应始终位于顶部.但是当文本很长时,视图应该在滚动视图中拉伸.
我发现没有相对布局的方式.我不知道这是一个错误或功能,但这种布局可以像我想要的那样扩展.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="top" />
<LinearLayout
android:id="@+id/bottomStuff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="bottom"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/radioAnswersGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</RadioGroup>
<LinearLayout
android:id="@+id/questionsNavigationGroup"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<Button
android:id="@+id/buttonPreviousQuestion"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1" />
<Button
android:id="@+id/buttonNextQuestion"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1" />
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
将此行添加到您的 TextView 元素中:
android:layout_above="@+id/radioAnswersGroup"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1816 次 |
| 最近记录: |