1. android九宮格xml怎麼寫
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:background="@drawable/yellow"
>
<ImageView android:id="@+id/ImageView01"
android:layout_width="100sp"
android:layout_height="100sp"
android:layout_gravity="center_vertical"
android:background="@drawable/a"></ImageView>
<GridView
android:id="@+id/gridview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
android:verticalSpacing="30dip"
android:horizontalSpacing="10dip"
android:columnWidth="90dip"
android:stretchMode="columnWidth"
android:gravity="center"
android:listSelector="@drawable/c"
>
</GridView>
</LinearLayout>
其中android:numColumns="3" 代表九宮格的列數 auto_fit時為自動
2、實現代碼
復制代碼 代碼如下:
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// 設置屏幕沒有標題
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// 去掉標題欄
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
GridView gridview = (GridView) findViewById(R.id.gridview);
// 創建一個數組列表對象
ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
/**
* 為每個格子添加內容
*/
for (int i = 1; i < 10; i++) {
HashMap<String, Object> map = new HashMap<String, Object>();// 建立hashmap對象
if (i == 1) {
map.put("ItemImage", R.drawable.g11);
map.put("ItemText", getResources()
.getString(R.string.gridview1));
}
if (i == 2) {
map.put("ItemImage", R.drawable.g12);
map.put("ItemText", getResources()
.getString(R.string.gridview2));
}
if (i == 3) {
map.put("ItemImage", R.drawable.g13);
map.put("ItemText", getResources()
.getString(R.string.gridview3));
}
if (i == 4) {
map.put("ItemImage", R.drawable.g14);
map.put("ItemText", getResources()
.getString(R.string.gridview4));
}
if (i == 5) {
map.put("ItemImage", R.drawable.g15);
map.put("ItemText", getResources()
.getString(R.string.gridview5));
}
if (i == 6) {
map.put("ItemImage", R.drawable.g16);
map.put("ItemText", getResources()
.getString(R.string.gridview6));
}
if (i == 7) {
map.put("ItemImage", R.drawable.g17);
map.put("ItemText", getResources()
.getString(R.string.gridview7));
}
if (i == 8) {
map.put("ItemImage", R.drawable.g18);
map.put("ItemText", getResources()
.getString(R.string.gridview8));
}
if (i == 9) {
map.put("ItemImage", R.drawable.g19);
map.put("ItemText", getResources()
.getString(R.string.gridview9));
}
lstImageItem.add(map);
}
/**
* 為GridView建立SimpleAdapter適配器
*/
// SimpleAdapter()中的五個參數分別是:第一個context,第二個數據資源,第三個每一個子項的布局文件,第四個每一個子項中的Key數組
// 第五個每一個子項中的Value數組
SimpleAdapter saImageItems = new SimpleAdapter(this, lstImageItem,
R.layout.grid_item, new String[] { "ItemImage", "ItemText" },
new int[] { R.id.ItemImage, R.id.ItemText });
gridview.setAdapter(saImageItems);// 添加適配器
gridview.setOnItemClickListener(new ItemClickListener());// 為每一個子項設置監聽
}
class ItemClickListener implements OnItemClickListener {
@SuppressWarnings("unchecked")
public void onItemClick(AdapterView<?> arg0,// The AdapterView where the
// click happened
View arg1,// The view within the AdapterView that was clicked
int arg2,// The position of the view in the adapter
long arg3// The row id of the item that was clicked
) {
HashMap<String, Object> item = (HashMap<String, Object>) arg0
.getItemAtPosition(arg2);
if (item.get("ItemText").equals(
getResources().getString(R.string.gridview1))) {
Toast.makeText(MainActivity.this, R.string.gridview1,
Toast.LENGTH_LONG).show();
}
if (item.get("ItemText").equals(
getResources().getString(R.string.gridview2))) {
Toast.makeText(MainActivity.this, R.string.gridview2,
Toast.LENGTH_LONG).show();
}
if (item.get("ItemText").equals(
getResources().getString(R.string.gridview3))) {
Toast.makeText(MainActivity.this, R.string.gridview3,
Toast.LENGTH_LONG).show();
}
if (item.get("ItemText").equals(
getResources().getString(R.string.gridview4))) {
Toast.makeText(MainActivity.this, R.string.gridview4,
Toast.LENGTH_LONG).show();
}
if (item.get("ItemText").equals(
getResources().getString(R.string.gridview5))) {
Toast.makeText(MainActivity.this, R.string.gridview5,
Toast.LENGTH_LONG).show();
}
if (item.get("ItemText").equals(
getResources().getString(R.string.gridview6))) {
Toast.makeText(MainActivity.this, R.string.gridview6,
Toast.LENGTH_LONG).show();
}
if (item.get("ItemText").equals(
getResources().getString(R.string.gridview7))) {
Toast.makeText(MainActivity.this, R.string.gridview7,
Toast.LENGTH_LONG).show();
}
if (item.get("ItemText").equals(
getResources().getString(R.string.gridview8))) {
Toast.makeText(MainActivity.this, R.string.gridview8,
Toast.LENGTH_LONG).show();
}
if (item.get("ItemText").equals(
getResources().getString(R.string.gridview9))) {
Toast.makeText(MainActivity.this, R.string.gridview9,
Toast.LENGTH_LONG).show();
}
}
}
}
2. AndroidManifest.xml 文件格式解析
圖片左側為解壓開apk後,茄陵AndroidManifest.xml的二進制內容,右側為各個chunk的解析。各顫滲戚個chunk和對應的二進制內容通過相同的顏色標記。
Android逆向三部曲之AndroidManifest.xml 文件格式 : https://www.jianshu.com/p/f0f4856866e0
AndroidManifest二進制喊團文件格式分析: https://bbs.pediy.com/thread-194206.html
手把手教你解析AXML: https://blog.csdn.net/beyond702/article/details/51830108?spm=1001.2014.3001.5502
大小端模式: https://blog.csdn.net/q2519008/article/details/80961176
ResourceTypes.h 源文件: http://androidxref.com/9.0.0_r3/xref/frameworks/base/libs/androidfw/include/androidfw/ResourceTypes.h
3. 如何正確地在 android 的 XML 中顯示多行文本
EditText 已定義到 wrap_content
的高度。這意味著它將會採取的內容,您的案例中的文本的大小。分配的初始空間只是一條線這樣它就會分配更多一旦你第二次。如果這不是設計問題,您可以為它分配到整個屏幕。
<EditText
android:id="@+id/noteText"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:ems="10"
android:gravity="right"
android:hint="متن خود را تایپ کنید"
android:inputType="textMultiLine"
android:padding="5dp" >
<requestFocus />
</EditText>
我改變了唯一的行:
android:layout_height="match_parent"
稍後編輯: 為了採取所有可能的空間,不會影響您執行此操作的按鈕:
android:layout_height="0dp"
android:layout_weight="1"
最後編輯由提問者:正確的答案是:
<EditText
android:id="@+id/noteText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:gravity="right"
android:hint="متن خود را تایپ کنید"
android:inputType="textMultiLine"
android:padding="5dp" >
<requestFocus />
</EditText>
4. android中的xml布局文件如何引用另一個xml布局文件
在一個xml文件中用include引入,例如textview中的include用法
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<include layout="@layout/include1"/>
<include layout="@layout/include2"/>
</LinearLayout>