第四天啦

时间:2020-08-12 21:32:37   收藏:0   阅读:116

今天学了,四大布局,还有如何自定义布局,和引入自定义布局,还有自定义控件,最后就是ListView  最后这个ListView学的迷迷糊糊,还有什么适配器,呕吼是我Java没学好吧emmm。

代码

布局

四大布局

引入自定义布局 (UICustomViews)

  1. 自定义标题栏布局   新建一个布局文件title.xml

?
  <Button
      android:id="@+id/title_back"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:layout_margin="5dp"
      android:background="#000000"
      android:text="back"
      android:textColor="#fff" />
?
  <TextView
      android:id="@+id/title_text"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:layout_gravity="center"
      android:gravity="center"
      android:text="Title Text"
      android:textColor="#fff"
      android:textSize="24sp"/>
?
  <Button
      android:id="@+id/title_edit"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_margin="5dp"
      android:layout_gravity="center"
      android:background="#000000"
      android:text="Edit"
      android:textColor="#fff"/>
?
<include layout="@layout/title"/>

自定义控件

public class TitleLayout extends LinearLayout {
?
?
  public TitleLayout(Context context, AttributeSet attrs){
      super(context,attrs);
      LayoutInflater.from(context).inflate(R.layout.title,this);
?
  }}

ListView(ListViewTest)

ListView的简单用法

    private String[] data = {"Apple","Banana", "hello", "nice to eet you", "good morning",
          "ambition", "stranger","Apple","Banana", "hello", "nice to eet you", "good morning",
          "ambition", "stranger","Apple","Banana", "hello", "nice to eet you", "good morning",
          "ambition", "stranger"};
?
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,data);
      ListView listView = findViewById(R.id.list_view);
      listView.setAdapter(adapter);
  }

 

自定义ListView界面

 

英语

原文:https://www.cnblogs.com/youseed/p/13492880.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!