如何使用LinearLayout创建此布局?

时间:2017-07-05 16:27:36

标签: android android-layout android-linearlayout

我想使用LinearLayout构建下面的布局。 enter image description here 我使用ConstraintLayout创建了它,但对我来说太长了。现在我想知道如何通过LinearLayout创建这种布局?可能吗?而且图片也必须有自己的大小,因为我认为如果是match_parent或wrap_content,图像的质量会很差。这是我尝试通过LinearLayout构建的方式,但结果太不同了。那么,我该怎么办?

    <?xml version="1.0" encoding="utf-8"?>
<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="com.example.abay.myeleven.MyTeamActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/attacks"
        android:orientation="horizontal"
        android:layout_marginTop="25dp"
        android:layout_weight="1"
        >

        <ImageButton
            android:layout_width="@dimen/player_width"
            android:layout_height="@dimen/player_height"
            android:src="@drawable/player_default"
            android:layout_weight="1"
            android:background="#FFF"
            />

        <ImageButton
            android:layout_width="@dimen/player_width"
            android:layout_height="@dimen/player_height"
            android:src="@drawable/player_default"
            android:layout_weight="1"
            android:background="#FFF"
            />
        <ImageButton
            android:layout_width="@dimen/player_width"
            android:layout_height="@dimen/player_height"
            android:src="@drawable/player_default"
            android:layout_weight="1"
            android:background="#FFF"
            />











    </LinearLayout>



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/midfields"
        android:orientation="horizontal"
        android:layout_marginTop="25dp"
        android:layout_weight="1"
        >
        <ImageButton
            android:layout_width="@dimen/player_width"
            android:layout_height="@dimen/player_height"
            android:src="@drawable/player_default"
            android:layout_weight="1"
            android:background="#FFF"
            />

        <ImageButton
            android:layout_width="@dimen/player_width"
            android:layout_height="@dimen/player_height"
            android:src="@drawable/player_default"
            android:layout_weight="1"
            android:background="#FFF"
            />
        <ImageButton
            android:layout_width="@dimen/player_width"
            android:layout_height="@dimen/player_height"
            android:src="@drawable/player_default"
            android:layout_weight="1"
            android:background="#FFF"
            />



        </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/defenders"
        android:orientation="horizontal"
        android:layout_marginTop="25dp"
        android:layout_weight="1"

        >
        <ImageButton
            android:layout_width="@dimen/player_width"
            android:layout_height="@dimen/player_height"
            android:src="@drawable/player_default"
            android:layout_weight="1"
            android:background="#FFF"
            />

        <ImageButton
            android:layout_width="@dimen/player_width"
            android:layout_height="@dimen/player_height"
            android:src="@drawable/player_default"
            android:layout_weight="1"
            android:background="#FFF"
            />
        <ImageButton
            android:layout_width="@dimen/player_width"
            android:layout_height="@dimen/player_height"
            android:src="@drawable/player_default"
            android:layout_weight="1"
            android:background="#FFF"
            />
        <ImageButton
            android:layout_width="@dimen/player_width"
            android:layout_height="@dimen/player_height"
            android:src="@drawable/player_default"
            android:layout_weight="1"
            android:background="#FFF"
            />


    </LinearLayout>



    <ImageButton
        android:layout_width="@dimen/player_width"
        android:layout_height="@dimen/player_height"
        android:src="@drawable/player_default"
        android:layout_weight="1"
        android:background="#FFF"
        android:layout_gravity="center"
        />





</LinearLayout>

1 个答案:

答案 0 :(得分:0)

只需在这些群组周围添加另一个public class PacketEncoder extends MessageToByteEncoder<Packet> { public PacketEncoder() { } @Override protected void encode(ChannelHandlerContext ctx, Packet packet, ByteBuf out) throws Exception { out.writeBytes(PacketUtil.convertPacketToBytes(packet, true)); } } ,并为LinearLayout添加一些填充。

ImageView