在java代码里面写布局 java语言中常用的布局管理器有哪些

.请简述如何在Java代码与XML文件中调用布局资源文件

步骤:

10年积累的成都网站制作、网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有新乡县免费网站建设让你可以放心的选择与我们合作。

1、在存放使用资源的res文件夹下的layout文件夹内新建一个XML布局文件,如命名为:page1.xml。

2、在存放资、代码的文件夹下下找到MainActivity.java,双击打开,在onCreate的方法内添加关联代码。

Android Studio如果在java中编写布局,代码放在哪个文件中?什么位置?

1.使用代码编写一个底部选项卡的布局

2.整个页面的容器布局(包含Fargment,分割线,选项卡)

private void initView(Context context) {

setBackgroundColor(0xfff6f6f6);

FrameLayout frameLayout=new FrameLayout(context);//选项界面容器

frameLayout.setId(FL_ID);

View lineView=new View(context);//分割线

lineView.setId(LINE_ID);

RelativeLayout.LayoutParams rlParams=new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

rlParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);

rlParams.addRule(RelativeLayout.ABOVE , LINE_ID);

lineView.setBackgroundColor(lineColor);

RelativeLayout.LayoutParams rlParams2=new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, DensityUtils.dip2px(context, 1));

rlParams2.addRule(RelativeLayout.ABOVE , TAB_ID);

addView(frameLayout, rlParams);//选项界面容器

addView(lineView,rlParams2);//分割线

//选项卡容器

linearLayout=new LinearLayout(context);

linearLayout.setBackgroundColor(tabBgColor);

linearLayout.setOrientation(LinearLayout.HORIZONTAL);

linearLayout.setGravity(Gravity.CENTER_VERTICAL);

linearLayout.setId(TAB_ID);

tabNum=tabIcos.length;

for (int i = 0; i tabNum; i++) {

View view = createIndicator(tabIcos[i], tabtxts[i], tabItemTvColor, "itemTag"+i, "icoTag" + i, "txtTag" + i);

view.setOnClickListener(OnClick);

if(i== nowTabIndex){//初始化选项卡

changeTab(view, i);

}

linearLay

怎么用java代码写一个线性布局;布局里面有两个按钮是水平的

android 使两个按钮水平排列的方法是使用lineLayout线性布局,如下代码:

?xml version="1.0" encoding="utf-8"?

LinearLayout xmlns:android=""

android:layout_width="fill_parent"

android:layout_height="match_parent"

android:background="@color/background"

android:orientation="vertical" 

View

android:layout_width="wrap_content"

android:layout_height="1.2px"

android:layout_marginBottom="7dp"

android:background="@color/white" /

LinearLayout

android:layout_width="fill_parent"

android:layout_height="79dp"

android:layout_weight="2"

android:orientation="horizontal"

android:layout_margin="10dp" 

Button

android:id="@+id/bt1"

android:layout_width="fill_parent"

android:layout_height="26dp"

android:background="@drawable/shape"

android:layout_weight="1"

android:text="确认对冲"

android:textColor="@color/white"

android:textSize="15dp" /

Button

android:layout_width="fill_parent"

android:layout_height="26dp"

android:background="@drawable/shapeyuanjiao"

android:layout_weight="1"

android:text="取消"

android:textColor="@color/white"

android:textSize="15dp" /

/LinearLayout

/LinearLayout

运行结果如下:


新闻名称:在java代码里面写布局 java语言中常用的布局管理器有哪些
转载注明:http://ybzwz.com/article/dosjisi.html