Android 布局设计-安卓
嗨,我想知道如何在android中制作这个布局。我想为下面的2列添加2个图像,它们可以单击。 这可能会有帮助Android 布局设计-安卓,android,android-layout,Android,Android Layout,嗨,我想知道如何在android中制作这个布局。我想为下面的2列添加2个图像,它们可以单击。 这可能会有帮助 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp">
<!-- Your code goes here -->
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:src="@drawable/img_1"
android:onclick="callFucntion1" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:src="@drawable/img_2"
android:onclick="callFucntion2" />
</LinearLayout>
</LinearLayout>
我想这就是你想要的。将图像放置在相应的图像布局元素中
android:src="........"
代码:
希望这有帮助。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/upper_linear_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="horizontal"
android:background="@android:color/white"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:orientation="horizontal"
android:id="@+id/colourlayout"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="50"
android:orientation="horizontal"
android:background="@color/colorAccent"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:id="@+id/image1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="50"
android:orientation="horizontal"
android:background="@color/colorPrimary"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:id="@+id/image2"
/>
</LinearLayout>
</LinearLayout></LinearLayout>
在这篇文章中,我使用了表格布局来满足您的要求…..在src中,您可以从drawable
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="150dp" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#c8c8c8" />
</RelativeLayout>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#dcdcdc"
android:gravity="center"
android:padding="20dip"
android:text="Row 2 column 1"
android:textColor="#000000"
android:src="@drawable/swara"/>
<ImageView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#d3d3d3"
android:gravity="center"
android:padding="20dip"
android:text="Row 2 column 2"
android:textColor="#000000"
android:src="@drawable/swara"/> </TableRow>
你试过什么?用于制作布局的拖放界面不起作用?目前我正在尝试“图像”按钮,我想知道实现这一点的最佳方法。您可能希望查看嵌套的线性布局或表格布局。发布代码请使用更多详细信息和示例解释您的问题。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/upper_linear_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="horizontal"
android:background="@android:color/white"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:orientation="horizontal"
android:id="@+id/colourlayout"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="50"
android:orientation="horizontal"
android:background="@color/colorAccent"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:id="@+id/image1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="50"
android:orientation="horizontal"
android:background="@color/colorPrimary"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:id="@+id/image2"
/>
</LinearLayout>
</LinearLayout></LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="150dp" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#c8c8c8" />
</RelativeLayout>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#dcdcdc"
android:gravity="center"
android:padding="20dip"
android:text="Row 2 column 1"
android:textColor="#000000"
android:src="@drawable/swara"/>
<ImageView
android:id="@+id/TextView04"
android:layout_weight="1"
android:background="#d3d3d3"
android:gravity="center"
android:padding="20dip"
android:text="Row 2 column 2"
android:textColor="#000000"
android:src="@drawable/swara"/> </TableRow>