導航:首頁 > 操作系統 > 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代碼相關的資料

熱點內容
兵器pdf 瀏覽:923
雲伺服器怎麼限制cpu 瀏覽:164
學信網用的什麼app 瀏覽:876
linux重啟命令apache 瀏覽:751
半夜解壓有什麼壞處 瀏覽:424
linux代理命令 瀏覽:637
調用tasking的編譯器編譯 瀏覽:292
青檸app是什麼 瀏覽:866
linuxapachephp56 瀏覽:397
安卓手機如何打開eng文件 瀏覽:24
看拉丁電視都用什麼app好 瀏覽:781
什麼是哲學pdf 瀏覽:509
hdfs的三個下載命令 瀏覽:525
java常用的排序演算法 瀏覽:359
51單片機連接adc 瀏覽:861
python命名變數報錯 瀏覽:122
安卓手機如何換windows系統 瀏覽:614
python中的類是什麼 瀏覽:632
我的英雄學院用哪個app可以看 瀏覽:37
excel插入選項卡對象命令 瀏覽:695