Android RelativeLayout align关注点
我正在玩android布局,并试图做一个简单的QA测试,但我不能得到正确的布局。我只是不知道如何调整这些东西,经过几个小时的斗争后,我几乎不需要什么帮助 以下是我想要的: 我得到的是: 以下是我的XML:Android RelativeLayout align关注点,android,layout,scrollview,android-relativelayout,Android,Layout,Scrollview,Android Relativelayout,我正在玩android布局,并试图做一个简单的QA测试,但我不能得到正确的布局。我只是不知道如何调整这些东西,经过几个小时的斗争后,我几乎不需要什么帮助 以下是我想要的: 我得到的是: 以下是我的XML: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rootLay
<?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>
答案和按钮应始终位于底部,问题应始终位于顶部。但当文本较长时,视图应在滚动视图内拉伸
编辑:
我找到了一条没有相关布局的路。我不知道这是一个bug还是一个特性,但是这个布局的缩放就像我想要的
<?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>
<?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>
将此行添加到TextView元素:
android:layout_above="@+id/radioAnswersGroup"
试试这个
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/scrollView1"
android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
android:layout_above="@+id/radioGroup1"
android:layout_alignParentRight="true">
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content" android:id="@+id/textView1"
android:text="TextView" android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
<RadioGroup android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/radioGroup1"
android:layout_above="@+id/spinner1" android:layout_alignParentRight="true"
android:layout_alignParentLeft="true">
<RadioButton android:layout_width="wrap_content"
android:id="@+id/radio0" android:layout_height="wrap_content"
android:text="RadioButton" android:checked="true" />
<RadioButton android:layout_width="wrap_content"
android:id="@+id/radio1" android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton android:layout_width="wrap_content"
android:id="@+id/radio2" android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton android:layout_width="wrap_content"
android:id="@+id/radio3" android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/button1"
android:text="Button" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/button2"
android:text="Button" android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<Spinner android:id="@+id/spinner1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
您可以尝试为
文本视图下方的线性布局
提供一个id,例如android:id=“@+id/bottomhalf”
,还可以定义android:layout\u下方=“@+id/textQuestion”
然后在您的TextView
中添加android:layout_over=“@+id/bottomhalf”
我认为以下更改将解决问题
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
而不是
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
我希望它能帮上忙。使用下面的布局,它会产生您在第一个链接中提到的输出。修改间距和可绘制范围。我希望它能帮助你
我在纵向模式下使用800X480分辨率检查输出,您必须根据设备分辨率修改布局宽度和高度
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="300px"
android:fillViewport="true" >
<TextView
android:id="@+id/textQuestion"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:text="TextView"
android:textSize="18dp" />
</ScrollView>
<RadioGroup
android:id="@+id/radioAnswersGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true">
<RadioButton android:layout_width="wrap_content"
android:id="@+id/radio0" android:layout_height="wrap_content"
android:text="RadioButton" android:checked="true" />
<RadioButton android:layout_width="wrap_content"
android:id="@+id/radio1" android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton android:layout_width="wrap_content"
android:id="@+id/radio2" android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton android:layout_width="wrap_content"
android:id="@+id/radio3" android:layout_height="wrap_content"
android:text="RadioButton" />
</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: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: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>
我找到了一条没有相关布局的路。我不知道这是一个bug还是一个特性,但是这个布局的缩放就像我想要的
<?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>
<?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>
我认为您应该使用以下方法:
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
事实上,我一直在从事一个类似的项目,与您的要求类似。
我在窗格上有两个微调器、按钮和图像视图等
请检查下面的xml布局代码,并尝试更改其中的几个参数以进行相应调整
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="3sp" >
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:baselineAligned="true"
android:orientation="horizontal" >
<ScrollView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<RelativeLayout
android:id="@+id/innerRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imgStartStop"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:contentDescription="@string/startstop"
android:onClick="startstop"
android:src="@drawable/start" />
<Button
android:id="@+id/btnStatus"
android:layout_width="220dp"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@id/imgStartStop"
android:onClick="showStatus"
android:text="@string/ontime" />
<ImageView
android:id="@+id/imgPushToTalk"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="@id/imgStartStop"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:contentDescription="@string/pushtotalk"
android:onClick="activatePushtoTalk"
android:src="@drawable/pushtotalkidle" />
<TextView
android:id="@+id/txtExpectedNumberofPassengers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/imgPushToTalk"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:text="@string/expectednumberofpassengers"
android:textSize="30sp" />
<TextView
android:id="@+id/txtNumberofPassengers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/imgPushToTalk"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@id/txtExpectedNumberofPassengers"
android:text="@string/numberofpassengers"
android:textColor="@color/greenText"
android:textSize="30sp" />
</RelativeLayout>
</ScrollView>
<fragment
android:id="@+id/mapFragment"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="3" />
</LinearLayout>
<TextView
android:id="@+id/txtTickerMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="@string/tickermessage"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
这将起作用:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/linear1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/linear2">
<RadioGroup android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioGroup1">
<RadioButton
android:layout_width="wrap_content"
android:id="@+id/radio0"
android:layout_height="wrap_content"
android:text="RadioButton"
android:checked="true" />
<RadioButton
android:layout_width="wrap_content"
android:id="@+id/radio1"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:layout_width="wrap_content"
android:id="@+id/radio2"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:layout_width="wrap_content"
android:id="@+id/radio3"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/linear3">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:text="Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="Button" />
<Spinner android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
您好,您使用哪种工具创建此屏幕布局?你已经使用了scrollview作为整个布局。为什么不将textview仅包装在scrollview中。因此,问题的文本只能滚动…我只是使用Paint.NET绘制图像。为什么我不把ScrollView仅仅用于文本,是因为我想让问题占据整个空间,如果这样做太长的话。