【问题标题】:Linear Layout UI Design线性布局UI设计
【发布时间】:2014-04-08 18:02:34
【问题描述】:

您好,我是 Android 开发的新手,我只有 15 岁。我一直在尝试制作类似于上面的 UI 设计,其中红色框是图像按钮。我已经尝试过重量等,但它每次都会切断图像的边缘。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearlayout_01"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearlayout_02"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1" >

        <ImageButton
            android:id="@+id/squads"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_weight="2"
            android:src="@drawable/squad" />

        <ImageButton
            android:id="@+id/results"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="10dp"
            android:layout_weight="2"
            android:src="@drawable/results" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearlayout_03"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1" >

        <ImageButton
            android:id="@+id/highlights"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_weight="4"
            android:src="@drawable/highlights" />

        <ImageButton
            android:id="@+id/fixtures"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="10dp"
            android:layout_weight="4"
            android:src="@drawable/fixtures" />
    </LinearLayout>

</LinearLayout>

【问题讨论】:

标签: android android-linearlayout


【解决方案1】:

试试这个布局结构,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearlayout_01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/linearlayout_02"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    >

    <ImageButton
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:src="@drawable/ic_launcher" />
</LinearLayout>

<LinearLayout
    android:id="@+id/linearlayout_03"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    >

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:layout_weight="2"
        android:src="@drawable/ic_launcher" />
</LinearLayout>

<LinearLayout
    android:id="@+id/linearlayout_04"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
     >

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:layout_weight="2"
        android:src="@drawable/ic_launcher" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher" />
</LinearLayout>

 <LinearLayout
    android:id="@+id/linearlayout_05"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    >

    <ImageButton
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:src="@drawable/ic_launcher" />
</LinearLayout>

这里,默认图像被视为 ic_launcher。

【讨论】:

    【解决方案2】:

    如果您只需要可点击的图片,请不要使用 ImageButtons,请使用 ImageViewclickable="true"。使用ImageView,您可以尝试不同的scaleType 属性值来实现您所需要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-05
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多