【发布时间】:2018-05-05 11:34:05
【问题描述】:
我正在尝试在我的 android 应用程序中实现这种格式。格式如下:-
[]
<LinearLayout 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"
android:orientation="vertical"
android:padding="20dp"
tools:context="com.example.nero.application.MainControl">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:padding="10dp">
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:text="Button"
android:textSize="20dp"
android:textColor="#f000"
android:background="@color/red"/>
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:text="Button"
android:textSize="20dp"
android:textColor="#f000"
android:background="@color/red" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:padding="10dp">
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:text="Button"
android:textSize="20dp"
android:textColor="#f000"
android:background="@color/red"/>
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:text="Button"
android:textSize="20dp"
android:textColor="#f000"
android:background="@color/red"/>
</LinearLayout>
我总是在我的工作中使用 LinearLayout,因为它易于理解并且在堆栈中工作。然而,RelativeLayout 对我来说有点复杂(个人)。这是我目前所做的,我还尝试在所有内容之上添加一个 FrameLayout 以显示最终按钮,但我无法获得准确的定位。
我试图避免的另一个问题是使这种设计适用于不同的屏幕尺寸。
任何帮助将不胜感激,谢谢!
【问题讨论】:
-
加完FrameLayout后能贴出代码吗?
-
对不起,伙计,我已经删除了 FrameLayout 代码,因为当我将 LinearLayout 放在 FrameLayout 中时,所有按钮都放在彼此的顶部。
-
这里你应该做的:把整个代码保持原样(甚至保持外部的LinearLayout)并将它放在FrameLayout中,确保视觉上没有任何变化。然后在 FrameLayout 内部但在 LinearLayout 外部添加一个按钮,并为 FrameLayout 提供重力中心。