編輯:關於Android編程
復制代碼 代碼如下:
package cn.aibow.android.layoutdemo1;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private int[] idarr = new int[]{R.id.tv1,R.id.tv2,R.id.tv3,R.id.tv4,R.id.tv5,R.id.tv6,R.id.tv7,R.id.tv8};
private int[] colorarr = new int[]{0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
private int[] bgarr = new int[]{0xFFFF6666,0xFF1e67c0,0xFFd47756,0xFF5a626f,0xFFee7434,0xFF3eadeb,0xFF0385fd,0xFF00a179};
private String[] textarr = new String[]{"通訊電腦","生活廚衛","家用電器","日用百貨","母嬰玩具","戶外體育","汽車配件","其它商品"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i=0;i<idarr.length;i++){
TextView tv = (TextView)findViewById(idarr[i]);
tv.setText(textarr[i]);
tv.setBackgroundColor(bgarr[i]);
tv.setTextColor(colorarr[i]);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView t = (TextView)v;
showMessage("您點擊的是 : "+t.getText().toString());
}
});
}
}
private void showMessage(String msg){
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
布局xml
復制代碼 代碼如下:
<LinearLayout 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"
android:orientation="vertical"
android:padding="6dp"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="@+id/tv1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_margin="6dp"
android:text="文本"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFFFFFFF"
android:textSize="28sp"
android:background="#FF000000"/>
<TextView
android:id="@+id/tv2"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_margin="6dp"
android:text="文本"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFFFFFFF"
android:textSize="28sp"
android:background="#FF000000"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="@+id/tv3"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_margin="6dp"
android:text="文本"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFFFFFFF"
android:textSize="28sp"
android:background="#FF000000"/>
<TextView
android:id="@+id/tv4"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_margin="6dp"
android:text="文本"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFFFFFFF"
android:textSize="28sp"
android:background="#FF000000"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="@+id/tv5"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_margin="6dp"
android:text="文本"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFFFFFFF"
android:textSize="28sp"
android:background="#FF000000"/>
<TextView
android:id="@+id/tv6"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_margin="6dp"
android:text="文本"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFFFFFFF"
android:textSize="28sp"
android:background="#FF000000"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="@+id/tv7"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_margin="6dp"
android:text="文本"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFFFFFFF"
android:textSize="28sp"
android:background="#FF000000"/>
<TextView
android:id="@+id/tv8"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_margin="6dp"
android:text="文本"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFFFFFFF"
android:textSize="28sp"
android:background="#FF000000"/>
</LinearLayout>
</LinearLayout>
效果圖
目前64bit android系統也慢慢的多了,看到也有apk聲稱支持64bit system,然後就往裡面打包搞了個arm64-v8a 目錄,放了個64bit的so,但
背景新項目的一個界面需要用到九宮格界面,每個Item包含一張圖片,下面是對應的文字描述,給每個Item設置點擊監聽器,當點擊時跳轉到相應的界面。於是想到使用Android
能夠實現自定義UI是android開發很重要的一個階段,下面就和大家一起學習、分享。首先官網上有兩篇文章: 1、Custom Components 2、Cre
下載必備的軟件包下載並安裝WebStorm7。WebStorm7目前的穩定版本是7.0.3。為什麼我們選擇WebStorm?因為它提供了許多功能,如JavaScript代