Pretty UI Design For Android and uiandroid

Source: Internet
Author: User

Pretty UI Design For Android and uiandroid

This article shows the effect from a foreign Internet. It feels very good. It simplifies the code and uses it. Let's take a look at it first:


The effect is quite good. Let's see how it is implemented:

Look at the text source, it is very simple, is an array:

<?xml version="1.0" encoding="utf-8"?><resources>    <string-array name="list_content">        <item>If I could save time in a bottle </item>        <item>the first thing that I\'d like to do </item>        <item>is to save every day until eternity passes away </item>        <item>just to spend them with you </item>        <item>If I could save time in a bottle </item>        <item>the first thing that I\'d like to do </item>        <item>is to save every day until eternity passes away </item>        <item>just to spend them with you </item>        <item>If I could make days last forever </item>        <item>if words could make wishes come true </item>        <item>I\'d save every day like a treasure and then </item>        <item>again I would spend them with you  </item>        <item>Thank you for comforting me when I\'m sad </item>        <item>Loving me when I\'m mad </item>        <item>Picking me up when I\'m down </item>        <item>Thank you for being my friend and being around </item>        <item>Teaching me the meaning of love </item>        <item>Encouraging me when I need a shove </item>        <item>But most of all thank you for  </item>        <item>Loving me for who I am  </item>    </string-array></resources>


The layout is also simple:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent">    <com.example.scrolltest.TopCenterImageView        android:id="@+id/bg"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:src="@drawable/image" />    <ListView        android:id="@+id/list"        android:layout_width="match_parent"        android:layout_height="match_parent"         android:divider="@null"/></FrameLayout>

Because we use a listview for display, it is the simplest to do so.


OK. Let's see what the program is like:

package com.example.scrolltest;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.AbsListView;import android.widget.AbsListView.LayoutParams;import android.widget.AbsListView.OnScrollListener;import android.widget.ArrayAdapter;import android.widget.ListView;public class MainActivity extends Activity {private TopCenterImageView bg;private ListView list;private View head;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);bg = (TopCenterImageView) findViewById(R.id.bg);list = (ListView) findViewById(R.id.list);list.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item,getResources().getStringArray(R.array.list_content)));head = new View(this);head.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 700));list.addHeaderView(head);list.setOnScrollListener(new OnScrollListener() {@Overridepublic void onScrollStateChanged(AbsListView view, int scrollState) {}@Overridepublic void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) {int top = head.getTop() / 2;bg.setTop(top);}});}}

There is a TopCenterImageView, which may be confusing. Let's see what it is:

package com.example.scrolltest;import android.content.Context;import android.graphics.Matrix;import android.util.AttributeSet;import android.widget.ImageView;/** * Custom view allowing an image to be displayed with a "top crop" scale type *  * @author Nicolas POMEPUY *  */public class TopCenterImageView extends ImageView {public TopCenterImageView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);setScaleType(ScaleType.MATRIX);}public TopCenterImageView(Context context, AttributeSet attrs) {super(context, attrs);setScaleType(ScaleType.MATRIX);}public TopCenterImageView(Context context) {super(context);setScaleType(ScaleType.MATRIX);}/** * Top crop scale type */@Overrideprotected boolean setFrame(int l, int t, int r, int b) {if (getDrawable() == null) {return super.setFrame(l, t, r, b);}Matrix matrix = getImageMatrix();float scaleFactor = getWidth() / (float) getDrawable().getIntrinsicWidth();matrix.setScale(scaleFactor, scaleFactor);setImageMatrix(matrix);return super.setFrame(l, t, r, b);}}

This rewritten ImageView is used to set the size of the ImageView so that it conforms to our background. The annotations are clearly written: custom view allowing an image to be displayed with a "top crop" scale type

At this time, let's look at the code again. The effect is still very good ~


Above.


What is the android ui?

UI developed by Google's mobile platform Android.

Www.wzsky.net/..4.html
Wu Tiantian [authoritative expert]

How can an independent Android developer learn the UI Design without any basic knowledge and Design works in line with Android Design?

UI. You have to accumulate in constant learning. The biggest headache is the setting of each property of the Control. Fortunately, each property of each control is available on the official website. First, master the commonly used UI and then learn about the custom layout, similar to custom controls

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.