【发布时间】:2020-06-12 06:38:43
【问题描述】:
我创建的一个适应性很小,但出于性能原因,我觉得它不是很有用。我添加了一些带有权重的空线性布局,以在顶部、左侧、右侧、中间和底部添加自适应边距。但我认为可能还有其他解决方案可以摆脱那些空布局,考虑到布局是自适应的。在此先感谢:)
<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"
tools:context=".StacksGameActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:orientation="horizontal"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
android:layout_margin="2dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
android:layout_margin="2dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
android:layout_margin="2dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_n" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
android:layout_margin="2dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="2dp"
android:background="@color/royal_blue_color">
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
</LinearLayout>
【问题讨论】:
-
你对其他android布局做过一些研究吗?你有什么特别的挣扎吗?你还没有真正解释你的问题是什么,你只是想要不同的解决方案:)
-
我想要的是,考虑到布局对不同屏幕尺寸的适应性,出于性能原因优化我的布局。这个是自适应的,但它可能导致我认为必须有一些解决方案来删除那些空布局
标签: android android-layout android-linearlayout