導航:首頁 > 操作系統 > android創建layout

android創建layout

發布時間:2022-08-10 18:19:44

android用代碼怎麼設置layout

代碼中可以布局layout,有專門的layout類,你查下資料吧,
不過還是建議盡量在xml中布局layout,代碼中會增加程序運行負擔,請採納謝謝

㈡ 新建Android項目layout什麼都沒有

你在向導里頭選了「empty project」之類的選項,所以不幫你生成layout。其實自己生成也很簡單,右鍵單擊layout,選擇new,選擇Android Layout File,選擇FrameLayout或者LinearLayout,就可以生成一個。然後new一個class,繼承自Activity,在OnCreate里頭調用setContentView(R.layout.XXX);就行了,其中XXX是你剛才建立的layout的文件名。

㈢ android中點擊哪個是把類和layout一起創建

一般創建project,開發環境會自動給mainActivity創建一個layout!但是之後自己創建類的時候,開發環境就不會自動再創建了!
不過,這個有插件可以實現,可以搜索一下,Android studio的常用插件試一試!

㈣ Android中,怎麼通過代碼設置layout背景

Android中view 通過代碼設置 layout首先確定要設置的layout是哪種layuot,這里以LinearLayout為例,首先步驟如下:1、首先在代碼中創建一個LinearLayout.LayoutParams對象,然後設置其寬高代碼如下:LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(20,30);2、然後設置margin、padding之類的屬性,如下:3、最後設置給一個控制項,如下:private TextView mTextView;mTextView = (TextView) findViewById(R.id.text);mTextView.setLayoutParams(ll);

㈤ android studio 怎麼在layout中創建文件夾

layout創建方式:
在res/layout目錄,右鍵 new XML 選擇layout即可
然後給layout起個名字,注意文件名只能是小寫,不能有大寫和中文

㈥ Android中view 怎樣通過代碼設置 layout

Android中view 通過代碼設置 layout首先確定要設置的layout是哪種layuot,這里以LinearLayout為例,首先步驟如下:

1、首先在代碼中創建一個LinearLayout.LayoutParams對象,然後設置其寬高代碼如下:

java">LinearLayout.LayoutParamsll=newLinearLayout.LayoutParams(20,30);

㈦ Android自定義layout怎麼寫

LinearLayout自定義方法有多種:
1、自定義xml布局,然後載入布局,自定義一個View繼承LinearLayout
2、在自定義控制項中聲明它的所有子元素,然後在Layout文件中像使用LinearLayout一樣去進行布局。

第二種比較煩 ,它需要在Layout文件中定義好子元素之後,要在代碼 onFinishInflate() 進行匹配子元素。

我就說說載入布局文件的方法吧。
首先:定義好layout文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingBottom="5dip"
android:paddingLeft="40dip"
android:paddingTop="5dip"
android:src="@drawable/right_icon" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dip"
android:text="主題"
android:textColor="#000000" />
<LinearLayout
android:layout_width="100dp"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingBottom="5dip"
android:paddingLeft="12dip"
android:paddingTop="5dip"
android:src="@drawable/home_icon" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingBottom="5dip"
android:paddingLeft="12dip"
android:paddingTop="5dip"
android:src="@drawable/add_icon" />
</LinearLayout>

</LinearLayout>
public class MyLinearLayout extends LinearLayout {

private ImageView imageView,iv_home,iv_add;
private TextView textView;

public MyLinearLayout (Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyLinearLayout (Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.actionbar, this);
imageView=(ImageView) findViewById(R.id.imageView1);
iv_home=(ImageView) findViewById(R.id.imageView2);
iv_add=(ImageView) findViewById(R.id.imageView3);
textView=(TextView)findViewById(R.id.textView1);

}

/**
* 設置圖片資源
*/
public void setImageResource(int resId) {
imageView.setImageResource(resId);
}

/**
* 設置顯示的文字
*/
public void setTextViewText(String text) {
textView.setText(text);
}

}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<cn.com.demo.view.MyLinearLayout
android:id="@+id/ll_actionbar"
android:layout_height="fill_parent<span style="font-family: Tahoma, 'Microsoft Yahei', Simsun;">" </span>
android:layout_width="wrap_content"
android:background="@drawable/bg"
/>
</LinearLayout>
接下來自定義一個MyLinearLayout繼承LinearLayout,並且載入剛剛寫好的layout文件。(比如http://www.tiecou.com)
public class MyLinearLayout extends LinearLayout {
private ImageView imageView,iv_home,iv_add;
private TextView textView;
public MyLinearLayout (Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyLinearLayout (Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.actionbar, this);
imageView=(ImageView) findViewById(R.id.imageView1);
iv_home=(ImageView) findViewById(R.id.imageView2);
iv_add=(ImageView) findViewById(R.id.imageView3);
textView=(TextView)findViewById(R.id.textView1);
}
/**
* 設置圖片資源
*/
public void setImageResource(int resId) {
imageView.setImageResource(resId);
}

/**
* 設置顯示的文字
*/
public void setTextViewText(String text) {
textView.setText(text);
}
}
最後,要的時候使用定義好的MyLinearLayout控制項。

㈧ android studio 新建項目 layout中為什麼有兩個xml文件

android studio 新建項目 layout中為有兩個xml文件是因為創建項目選擇的布局文件問題,有些布局文件創建出來有兩個甚至更多,要創建項目中只有Layout布局中只有一個XML文件,只需要在選擇布局的時候選擇Empty Activity即可,操作步驟如下:

1、雙擊打開Android studio之後選擇start a new Android Studio project,如下圖:

閱讀全文

與android創建layout相關的資料

熱點內容
歐美愛情喜劇電影 瀏覽:194
主角叫李天的小說 瀏覽:574
台灣風情片 瀏覽:468
xcode新版編譯運行 瀏覽:182
原版純英文字幕電影 瀏覽:231
阿里雲如何做到雲伺服器獨立ip 瀏覽:708
單片機進制教案 瀏覽:476
有什麼好的演算法書 瀏覽:157
到達市電影院英語 瀏覽:135
韓國電影男的進健房找女教練 瀏覽:10
國內十個免費網站 瀏覽:703
雙女主的小說 瀏覽:545
邱淑貞拍過的3級 瀏覽:661
午夜電影在線觀看網頁 瀏覽:221
美國男同電影 瀏覽:558
主角穿越電影強化性能力 瀏覽:837
主角林楓穿越到異界 瀏覽:469
小說下載書包網txt在線下載 瀏覽:969
肉很多很欲的高質量現言 瀏覽:428
電影愛情來得不準時塞爾維亞 瀏覽:748