导航:首页 > 操作系统 > 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相关的资料

热点内容
银河麒麟下编译qt源码 浏览:162
读单片机的flash 浏览:838
安全不收费的看片网站 浏览:945
单片机显示屏加排阻 浏览:729
新京报pdf 浏览:403
日本韩国推理片电影免费 浏览:823
c语言求n的阶乘递归算法 浏览:203
服务器未回应是什么原因 浏览:816
缥缈白姬和轩之结局 浏览:593
全球票房在哪里查 浏览:781
宝书网小说 浏览:812
无水印高清电影 浏览:772
拼车夫妇韩国中文 浏览:783
怎么在设置开启app内购买 浏览:335
三个女人在监狱是什么电影曹查理演的 浏览:434
复爱旧仇电影日本 浏览:210
军用压缩饼干和军粮 浏览:596
韩国成人百合电影 浏览:271
戴拿奥特曼客串过的电影 浏览:403