導航:首頁 > 操作系統 > android代碼

android代碼

發布時間:2022-01-28 21:47:56

android 代碼裡面怎麼設置

在線性布局LinearLayout里加入view比較簡單,因為屬性比較少,布局簡單
示例,加入一個TextView

1
2
3
4
5

LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
TextView tv = new TextView(this);
tv.setText("hello,world");
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layout.addView(tv,lp);

在相對布局中RelativeLayout中加入view,屬性較多
示例,加入TextView和Button,讓TextView居中,並且設置Button在TextView的下方

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

RelativeLayout layout;
TextView tv = new TextView(this);
tv.setText("hello,world");
Button btn = new Button(this);
btn.setText("button");
tv.setId(0x011);
btn.setId(0x012);
LayoutParams tvLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
LayoutParams btnLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//添加布局規則,居中於父類
tvLp.addRule(RelativeLayout.CENTER_IN_PARENT,RelativeLayout.TRUE);
//添加布局規則,在tv的下方
btnLp.addRule(RelativeLayout.BELOW, tv.getId());
layout.addView(tv,tvLp);
layout.addView(btn,btnLp);

public void addRule(int verb, int anchor) 方法就是給view設定布局規則,verb是規則屬性,就是xml文件中的各種屬性值,anchor是依靠的view的id或者比如上面的RelativeLayout.CENTER_IN_PARENT的時候就是設置true或false

⑵ android代碼,這是什麼意思

登陸,主要看看HttpUtil裡面的BASE_URL
這個就是登陸的地址

⑶ 如何打開android 源代碼

可以用配置了Android環境的eclipse,也可以直接用Android studio,都可以直接導入項目源碼

⑷ android 代碼中的 @ 符號什麼意思

xml中的@就是在哪個文件裡面找變數
android:text="@string/hello"就是text的值是 在string文件里的 hello變數

⑸ Android代碼中修改系統時間

android下修改時間的代碼:

java">publicvoidtestDate(){
try{
Processprocess=Runtime.getRuntime().exec("su");
Stringdatetime="20131023.112800";//測試的設置的時間【時間格式yyyyMMdd.HHmmss】
DataOutputStreamos=newDataOutputStream(process.getOutputStream());
os.writeBytes("setproppersist.sys.timezoneGMT ");
os.writeBytes("/system/bin/date-s"+datetime+" ");
os.writeBytes("clock-w ");
os.writeBytes("exit ");
os.flush();
}catch(IOExceptione){
e.printStackTrace();
}
}

⑹ android在代碼里添加按鈕

你好:

不太理解你的意思,給你寫了個小Demo 是用代碼初始化button

{

privateButtonbtn;
privateRelativeLayoutlayout;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
layout=(RelativeLayout)this.findViewById(R.id.layout);
//初始化button加入布局
btn=newButton(this);
btn.setBackgroundResource(R.drawable.ic_launcher);
layout.addView(btn);
}

}
希望能幫到你

⑺ android開發中 改變背景的代碼是什麼

在Java代碼中設置

背景資源如果在res drawable下面:

view.setBackgroundResource(R.drawable.img);

背景資源如果是顏色值:

view.setBackgroundColor(R.color.white);

背景資源如果是drawable對象:

view.setBackground(drawable);

在xml中設置

android:backgroud="@drawable/img"

android:backgroud="@color/white"

⑻ android 代碼分享有哪些

去GitHub上面看,上面的代碼很全,基本都是大牛寫的

⑼ android 代碼中如何注釋多行

⑽ Android如何在java代碼中設置margin

在xml里設置margin,如:<ImageView android:layout_margin="5dip" android:src="@drawable/image" />但是有些情況下,需要在java代碼里來寫,通過查閱android api,android.view.ViewGroup.MarginLayoutParams有個方法setMargins(left, top, right, bottom). 其直接的子類有: FrameLayout.LayoutParams, LinearLayout.LayoutParams and RelativeLayout.LayoutParams.:LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);lp.setMargins(10, 20, 30, 40);imageView.setLayoutParams(lp);

閱讀全文

與android代碼相關的資料

熱點內容
香港伺服器如何做代理 瀏覽:199
pdf寫入 瀏覽:984
高爾夫電台怎麼添加到文件夾 瀏覽:237
四川麻將一般下哪個app 瀏覽:862
反編譯exe腳本 瀏覽:460
源碼文件夾怎麼編譯到固件中 瀏覽:912
ERp列印伺服器錯誤怎麼弄 瀏覽:113
蚌埠u盤加密軟體有哪些 瀏覽:178
前端如何認證伺服器 瀏覽:554
linux切換db2用戶命令 瀏覽:308
相片如何用電解壓 瀏覽:906
碩士程序員去學校當老師 瀏覽:120
pythonstr提取到字典 瀏覽:820
程序員那麼可愛有人看上陸漓了 瀏覽:878
php正則提取圖片 瀏覽:105
pythonlinuxdjango 瀏覽:564
php中文返回亂碼 瀏覽:91
宿舍裝的電信怎麼加密 瀏覽:746
為什麼壓縮文件解壓後變少了 瀏覽:426
現在安卓充電器普遍是什麼型號 瀏覽:717