android测验按钮正在改变大小和位置,如何解决这个问题
我正在用android做一个测试,所有的测试都是为了让布局看起来干净。测验布局有一个问题和4个答案选择,所有内容都是垂直的,看起来像一个经典的测验应用程序 问题是,每个问题的布局都会发生变化,按钮会上下跳跃,并根据文本的行数(有些问题和答案有2-3行)改变大小(高度)。我希望所有元素保持相同的高度和位置,无论文本的数量如何,但无论我尝试了什么,都失败了 我总是检查多个来源,但决定写一个问题。有人能帮忙吗?这是.xml文件。代码现在一团糟,它经历了一系列的实验,对不起android测验按钮正在改变大小和位置,如何解决这个问题,android,android-studio,android-layout,Android,Android Studio,Android Layout,我正在用android做一个测试,所有的测试都是为了让布局看起来干净。测验布局有一个问题和4个答案选择,所有内容都是垂直的,看起来像一个经典的测验应用程序 问题是,每个问题的布局都会发生变化,按钮会上下跳跃,并根据文本的行数(有些问题和答案有2-3行)改变大小(高度)。我希望所有元素保持相同的高度和位置,无论文本的数量如何,但无论我尝试了什么,都失败了 我总是检查多个来源,但决定写一个问题。有人能帮忙吗?这是.xml文件。代码现在一团糟,它经历了一系列的实验,对不起 <RelativeLa
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="hr.prepoznajmoenasilje.Kviz">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="@+id/pitanje"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginTop="25dp"
android:layout_marginEnd="25dp"
android:layout_marginBottom="25dp"
android:text="TextView"
android:textSize="18sp" />
<Button
android:id="@+id/o1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button"
android:textSize="14sp" />
<Button
android:id="@+id/o2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button"
android:textSize="14sp" />
<Button
android:id="@+id/o3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button"
android:textSize="14sp" />
<Button
android:id="@+id/o4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button"
android:textSize="14sp" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
</LinearLayout>
</RelativeLayout>
这就是我的想象。我设法让它看起来像那样,但不是没有高度变化和位置移动的问题。
解决了这个问题,只是将textview的高度设置为一个恒定的高度,而不是包装内容,从而使其无法四处移动。我知道这是件很愚蠢的事,但我想不通,对不起 您需要设置按钮高度0dp并固定文本视图大小,请尝试此…
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/motion_anim"
tools:context="hr.prepoznajmoenasilje.Kviz">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp">
<TextView
android:id="@+id/pitanje"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="TextView"
android:textSize="18sp" />
<Button
android:id="@+id/o1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button"
android:textSize="14sp" />
<Button
android:id="@+id/o2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button"
android:textSize="14sp" />
<Button
android:id="@+id/o3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button"
android:textSize="14sp" />
<Button
android:id="@+id/o4"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
那么,您打算如何处理查看非常大的文本?例如3-4行?你想在文本视图中滚动吗?@Azhar92这些问题大多有较大的文本,因为它们的字体更大,但按钮大多有1-2个,但当它们有2个时,它们已经弄乱了位置和高度。我更喜欢将按钮和问题文本视图的默认高度设置得足够大,这样无论有多少文本,所有内容都可以放进去。