(Android Control) interface layout for GridView (grid effect)

Source: Internet
Author: User

1Effects to be achieved:

To meet the business needs, you need to achieve the mesh effect. Specifically, the screen is divided into two rows, with one picture centered in the middle.

Additional requirements: when considering the interface design, mobile phone screens with different resolutions cannot be laid out in a fixed position.

 

Implementation interface:

 

2Magic control property: layout_weight

Layout_weightAttribute

Attribute meaning: Set the space allocated to the control. The default value is 0, and the control remains unchanged. If the property is greater than 0, the remaining controls on the screen are allocated to the control.

 

3Solution:

[General implementation method]

Set a horizontal layout, place controls, and set the interval between controls. However, for screens of different sizes, do multiple sets of interfaces.

 

[Solution of this article]

Set a horizontal layout, add several linear la s to the layout, set the property layout_weight = 1 in a unified manner, center, and place the required controls in the linear layout.Layout_weightThis attribute allows linear layout to be classified and ensures that the required controls are not out of shape.

 

 

4Practical implementation code:

 

   <LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_marginTop="15dp"
android:layout_height="wrap_content" >

<LinearLayout
android:id="@+id/linearLayout_n1"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_weight="1"
android:gravity="center"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/img_1"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:focusable="true"
android:clickable="true"
android:tag="1"
android:background="@drawable/imgselect"
android:src="@drawable/sl1_1" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout_n2"
android:layout_width="fill_parent"
android:layout_weight="1"
android:orientation="horizontal"

android:gravity="center"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/img_2"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:tag="2"
android:focusable="true"
android:clickable="true"
android:background="@drawable/imgselect"
android:src="@drawable/sl1_2" />
</LinearLayout>
</LinearLayout>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.