import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore.Images;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
public class Test extends Activity {
/** Called when the activity is first created. */
LinearLayout linearLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
linearLayout= new LinearLayout(this);//线性布局
LinearLayout.LayoutParams layoutParams = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ImageButton imageButton_1 = new ImageButton(this);
imageButton_1.setLayoutParams(layoutParams);
imageButton_1.setImageDrawable(getResources().getDrawable(
R.drawable.icon));
linearLayout.addView(imageButton_1);
imageButton_1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = new AlertDialog.Builder(Test.this)
.setTitle("提示")
.setMessage("我是ImageButton1")
.setPositiveButton("确定",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
}
}).create();//创建按钮
dialog.show();
}
});
setContentView(linearLayout);
}
public LinearLayout getView(){
return linearLayout;
}
}
分享到:
相关推荐
Android程序源码--代码布局,Android程序源码--代码布局
Android代码实现布局
习惯了用xml来写布局的,再用代码来写布局,恐怕会很类。但毕竟有时候,我们还是需要用到代码来写布局。...代码布局与xml布局有很多相似点,在大多数方法上都可以直接用,只有个别方法的写法不太一样
Android 通用圆角布局,快速实现圆角需求。 之前做项目的时候有圆角相关需求,在网上找了很多方案都不够满意,于是自己做了一个,目前已经使用了一段时间,更新了多个版本,我遇到的问题都进行了修复,并且添加了很...
对于android常用的布局管理器的代码练习,主要以xml文件为主,也有部分的Activity的操作!
android框架布局的使用,对框架布局理解的好例子,可以作为初学者的好教程。
Android程序布局入门,熟练掌握,Android布局,有利于以后Android的学习!Android23中布局,最详细,最精炼,敲打几遍代码,就可以熟练地掌握Android。
用Android Studio 2.3.3做的表格布局例子,主要用到、标签,还有android:shrinkColumns="0,1,2"、android:layout_column="0"等设置。
Android优化布局文件的代码例子。用于演示与布局相关的ViewStub、style、Theme等特性的用法。
可以参考对应的文章有描述。 地址:http://blog.csdn.net/gufengcangying/article/details/24883831
Android使用文本输入布局TextInputLayout的代码例子。用于演示文本输入布局TextInputLayout和文本输入编辑框TextInputEditText对编辑框的功能增强。
A FlowLayout for Android, which allows child views flow to next row when there is no enough space. The spacing between child views can be calculated by the FlowLayout so that the views are evenly ...
android布局案例源代码,其中有树形布局,仿写TabHost的源码...........
Android页面布局代码,欢迎下载,也期待您一起分享您的精华,期待下载您的好资料
用Android Studio 2.3.3做的绝对布局例子,主要用到<AbsoluteLayout></AbsoluteLayout>标签、android:text、 android:layout_x和android:layout_y设置。
Android使用协调布局CoordinatorLayout的代码例子。用于演示CoordinatorLayout的基本用法,以及悬浮按钮FloatingActionButton、底部弹窗BottomSheetBehavior的使用方法。
Android布局实验 主界面 运行APP,主界面如下图。图里有三个按钮,分布对应三种布局,点击按钮,跳转到对应布局界面。 线性布局 点击线性布局按钮,跳转到线性布局界面,如下图。 相对布局 返回主界面,点击相对...
Android中使用RelativeLayout完成梅花布局的代码清单.pdf 学习资料 复习资料 教学资源
老罗Android视频开发教程 android常用布局的介绍代码,很不错的教程代码。
2. 在布局文件中引用 xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@ id/item_one" android:layout_width="match_parent" android:layout_height="wrap_content" leon:leftIcon="@...