Android custom tags are used to implement flat uidesign and androidui

Source: Internet
Author: User

Android custom tags are used to implement flat uidesign and androidui
August 6, 2014 11:06:44

Android uses custom tags to implement a flat uidesign:
1. Custom tags in the attrs. xml file
For example:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>


<Declare-styleable name = "first">
// Reference is referenced from string. xml.


<Attr name = "name" format = "reference"/>
<Attr name = "age">
// Flag is defined by yourself, similar to android: gravity = "top"
<Flag name = "child" value = "10"> </flag>
<Flag name = "yong" value = "18"> </flag>
<Flag name = "oldman" value = "60"> </flag>
</Attr>
// Dimension refers to the content referenced from dimension. xml.
<Attr name = "testSize" format = "dimension"> </attr>
</Declare-styleable>


</Resources>
2. Use custom tags in the layout file to assign values to tag attributes.
For example:
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
// Com. example. declarestyleabletest is the root path in the configuration file xmlns: test = "http://schemas.android.com/apk/res/com.example.declarestyleabletest"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: orientation = "vertical">
// For more information about MyTest, see the following.
<Com. example. declarestyleabletest. MyTest
Android: id = "@ + id/tvTest"
Test: name = "@ string/name"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/test"
Test: age = "oldman"
Test: testSize = "@ dimen/size"/>


</LinearLayout>
3. MyTest. java: You can obtain the attribute value in the layout file in the class. After obtaining the value, you can assign a value to the TextView attribute and modify the style.
For example:
Package com. example. declarestyleabletest;
Import android. content. Context;
Import android. content. res. TypedArray;
Import android. util. AttributeSet;
Import android. widget. TextView;


Public class MyTest extends TextView {


Public MyTest (Context context, AttributeSet attrs ){
Super (context, attrs );


TypedArray tArray = context. obtainStyledAttributes (attrs,
R. styleable. first );
String name = tArray. getString (R. styleable. first_name );
Int age = tArray. getInt (R. styleable. first_age, 100 );
// Int dimen = tArray. getInt (R. styleable. first_testSize, 110 );
System. out. println ("name:" + name + "age:" + age + "dimen :");
// Reuse StyledAttributes
TArray. recycle ();

}
}
4. Use id: tvTest in main. activity to use a view object with a modified style, such as TextView in this example.

The following two demos are attached. The first one is the assignment and retrieval of simple custom tags, and the second is the implementation of the flat Ui. You can refer to them.

Flat:


Http://download.csdn.net/detail/u014071669/7720493


What is flat UI?

Abandon all effects and completely flat

In 2013, the UI design began to become popular and flat?

I personally think that both design and other fields follow the philosophy of "no. After reading the pseudo-materialized uidesign for a long time, there will certainly be Aesthetic Fatigue. The flat design will certainly give people a new feeling. Every new design trend needs to be led by someone, that is, the authority in the eyes of the public. The new trend must be more attractive, but it cannot be ruled out by the impetus of the public follow-up. Just like the changing trend in the history of design, the transition from the art and crafts period with particular emphasis on decoration to the modernization of the form following the function, when the masses were fed up with cold products, then they produced a strong POP design style (although the pop style was just a short turmoil in the design history ), later on, post-modern architecture emphasizes both form and function. All of this shows that historical trends are evolving in the negative and spiraling way.

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.