【发布时间】:2021-10-16 15:52:12
【问题描述】:
下面是我的 XML 代码。我想通过留一些边距在线性布局(id:inside_linear)上方显示吐司。我知道我们可以使用 toast 的 setGravity() 方法。但是如何计算 yoffset?
<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"
tools:context=".MainActivity"
android:id="@+id/relative">
<LinearLayout
android:id="@+id/outside_linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
android:weightSum="10">
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"/>
<LinearLayout
android:id="@+id/inside_linear"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:gravity="center_horizontal">
.....
</LinearLayout>
</RelativeLayout>
【问题讨论】:
-
这能回答你的问题吗? How to change position of Toast in Android?
标签: java android xml android-layout