Android Issues 总结


[TOC]


DateTimePicker Control

自定义对话框

How to draw rectangle in XML?

We can create a new XML file inside the drawable folder, and add the following code, then save it as rectangle.xml.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid
        android:color="@android:color/transparent" />
    <stroke
        android:width="2dip"
        android:dashWidth="2dp"   
        android:dashGap="5dp"    
        android:color="#ff0000"/>
</shape>

To use it inside a layout we would set the android:background attribute to the new drawable shape,like the following code segment.

<ImageView
	android:id="@+id/rectimage"
	android:layout_height="100dp"
	android:layout_width="100dp"
	android:src="@drawable/rectangle">
</ImageView>

finally,have a fun!

Link: http://stackoverflow.com/questions/10124919/can-i-draw-rectangle-in-xml

How to change “shape”(in XML) color dynamically?

The “Shape” code in circle2.xml is as like the following segments:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/shape_circle2"
    android:shape="oval"
    android:useLevel="false" >	        
    <solid
        android:color="@android:color/transparent" />	    
    <stroke
        android:width="1dp"
        android:color="#00ff00"/>
    <size
        android:width="55dp"
        android:height="55dp"/>    
</shape>

The code using “Shape” is as follows:

<ImageView
	android:id="@+id/circle_img"
	android:layout_height="50dp"
	android:layout_width="50dp"
	android:background="@drawable/circle">
</ImageView>

And we can modify the “Shape” color simply like this:

ImageView imgviewCircle  = (ImageView)findViewById(R.id.circle_img);
GradientDrawable backgroundGradient = (GradientDrawable)imgviewCircle.getBackground();
backgroundGradient.setColor(Color.GREEN);

Note: It must be the attribute android:background of ImageView that use the “Shape” as long as we modify the “Shape” color like that!

Link: http://stackoverflow.com/questions/7164630/how-to-change-shape-color-dynamically

Android设置textView水平居中显示

  • 让textView里面的内容水平居中:android:gravity=”center_horizontal”
  • 让textView控件在它的父布局里水平居中:android:layout_gravity=”center_horizontal”

Using lists in Android (ListView) - Tutorial

Link: http://www.vogella.com/tutorials/AndroidListView/article.html




^