Android 如何防止一个文本视图将另一个文本视图推出屏幕?
[已解决]标记了工作解决方案@吉宾·托马斯:这个建议同样有效(类似) 下面我发布了一个问题,当分数增加时会出现,使其扩大,从而将另一个文本视图推出屏幕。我尝试过用各种方式改变文本视图本身和包装它们的布局的宽度和高度,但没有任何运气 问题:有人找到了一个很好的解决方案,如何设置我的布局和/或文本视图的宽度和高度,以防止评分文本视图将生活文本视图推出屏幕 这是我的XML文件: 下面的布局和文本视图都位于另一个布局内(包括4个按钮,一个imageview和另一个textView-代码中排除)Android 如何防止一个文本视图将另一个文本视图推出屏幕?,android,Android,[已解决]标记了工作解决方案@吉宾·托马斯:这个建议同样有效(类似) 下面我发布了一个问题,当分数增加时会出现,使其扩大,从而将另一个文本视图推出屏幕。我尝试过用各种方式改变文本视图本身和包装它们的布局的宽度和高度,但没有任何运气 问题:有人找到了一个很好的解决方案,如何设置我的布局和/或文本视图的宽度和高度,以防止评分文本视图将生活文本视图推出屏幕 这是我的XML文件: 下面的布局和文本视图都位于另一个布局内(包括4个按钮,一个imageview和另一个textView-代码中排除) 这将
这将解决您的问题
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="Current Score"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentScoreEasy"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Scrore"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="Lives"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lives 5"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
如果您还有其他疑问,请删除我添加的字符串。请随时记下以下内容,这将解决您的问题
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="Current Score"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentScoreEasy"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Scrore"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="Lives"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lives 5"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
如果您还有其他疑问,请删除我添加的字符串。请随意记下以下内容,尝试此布局:
正确使用android:weightSum
和android:layout\u weight
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="left"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:id="@+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="SCORE"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentScoreEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SCORE"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:id="@+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="Lives"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lives"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
输出:
尝试以下布局:
正确使用android:weightSum
和android:layout\u weight
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="left"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:id="@+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="SCORE"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentScoreEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SCORE"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:id="@+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="Lives"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lives"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
输出:
请确保使用适当的重量,并进行如下更改:
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:padding="10dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:orientation="horizontal">
<TextView
android:id="@+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="current_score"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentScoreEasy"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content"
android:text="current_score_0"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:id="@+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="lives"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lives_5"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
请确保使用适当的重量,并进行如下更改:
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:padding="10dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:orientation="horizontal">
<TextView
android:id="@+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="current_score"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentScoreEasy"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content"
android:text="current_score_0"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:id="@+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="lives"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lives_5"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
只需给出线性布局,布局_weight=“5”。。像 android:layout\u weight=“3”并制作android:layout\u width=“0px” 注意=“根据您的间距设置布局权重”
安装这两个文本视图的线性布局只需给出线性布局,Layout\u weight=“5”。。像
Simply replace your current score linear layout with this relative layout and you are done.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:layout_alignParentLeft="true"
android:text="current_score"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentScoreEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="current_score_0"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</RelativeLayout>
android:layout\u weight=“3”并制作android:layout\u width=“0px”
注意=“根据您的间距设置布局权重”
您安装这两个文本视图的线性布局
只需将当前的分数线性布局替换为此相对布局,您就完成了。
Simply replace your current score linear layout with this relative layout and you are done.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:layout_alignParentLeft="true"
android:text="current_score"
android:textColor="@android:color/black"
android:textSize="20sp" />
<TextView
android:id="@+id/currentScoreEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="current_score_0"
android:textColor="@android:color/holo_red_dark"
android:textSize="20sp" />
</RelativeLayout>
只需将当前分数线性布局替换为此相对布局即可。
只需将当前分数线性布局替换为此相对布局,并将android:layout\u alignParentLeft=“true”
设置为currentScoreText,将android:layout\u alignParenRight=“true”
设置为currentScoreEasy。请检查完整块以获取答案。只需将当前分数线性布局替换为此相对布局,并将android:layout\u alignParentLeft=“true”
设置为currentScoreText,将android:layout\u alignParenRight=“true”
设置为currentScoreEasy。请检查完整的区块以获得答案。谢谢您的建议,我已经标记了工作解决方案。但我也想尝试一下,不幸的是,它不起作用。无论如何谢谢你。@FisnikB。你找到了很好的解决方案。我正在用这个,它对我来说很好用。我已经根据你的需要做了一些编辑。你能试试吗?谢谢,我假设这个问题是因为您不知道我其余的代码是什么样子的。我猜这就是让你讨厌的地方。你现在刚做了一个新的编辑?谢谢你的建议,我已经标记了有效的解决方案。但我也想尝试一下,不幸的是,它不起作用。无论如何谢谢你。@FisnikB。你找到了很好的解决方案。我正在用这个,它对我来说很好用。我已经根据你的需要做了一些编辑。你能试试吗?谢谢,我假设这个问题是因为您不知道我其余的代码是什么样子的。我猜这就是让你讨厌的地方。您现在刚刚进行了新的编辑?谢谢您的建议,标记了有效的解决方案。但我也试过你的,效果也一样好!谢谢你的帮助!感谢您的建议,标记了工作解决方案。但我也试过你的,效果也一样好!谢谢你的帮助!