移动互联网开发入门Android Studio ,适合刚学习的
目录1.创建Android的具体步骤1.第一步创建项目2.安装JDK,一直往下操作3.创建虚拟机4.编写与运行LinearLayout1.orientation的使用2.gravity的使用3.layout_gravity的使用4.layout_weight的知识1.创建Android的具体步骤1.第一步创建项目2.安装JDK,一直往下操作3.创建虚拟机4.编写与运行LinearLayout
目录
目录
Waiting for all target devices to come online,怎么解决
1.创建Android的具体步骤
1.第一步创建项目
2.安装JDK,一直往下操作
3.创建虚拟机
4.编写与运行
LinearLayout
常见属性:
(1)orientation布局组件的排列方式
(2)gravity控制组件所包含的子元素对齐方式
(3)layout_gravity控制该组件在父容器的对其方式
(4)background设置背景图片或颜色
(5)layout_weight权重,用来等比例的划分
1.orientation的使用
2.gravity的使用
(属性值有:center水平垂直居中;center_horizontal水平居中;center_vertical垂直居中;right水平右;bottom底部...)
3.layout_gravity的使用
控制自己的
4.layout_weight的知识
layout_weight就是将剩余的容量,进行等比例的划分
如何实现横竖屏切换
首先
其次覆盖onConfigurationChanged方法
ListView
Bean
package com.example.listview;
public class Bean {
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
MainActivity
package com.example.listview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import java.sql.Array;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private List<Bean> data=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for (int i=0;i<100;i++){
Bean bean=new Bean();
bean.setName("user"+i);
data.add(bean);
}
ListView listview=findViewById(R.id.lv);
listview.setAdapter(new MyAdapter(data,this));
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Log.e("onclick",""+i);
}
});
}
}
MyAdapter
package com.example.listview;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public class MyAdapter extends BaseAdapter {
private List<Bean> data;
private Context context;
public MyAdapter(List<Bean> data,Context context) {
this.data=data;
this.context=context;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
//返回item条目
if(view==null) {
view = LayoutInflater.from(context).inflate(R.layout.list_item, parent, false);
}
TextView textView=view.findViewById(R.id.tv);
textView.setText(data.get(position).getName());
return view;
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent">
<ListView android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</LinearLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ddd"
android:height="40dp"/>
</LinearLayout>
RecyclerView
Bean
package com.example.recyclerview;
public class Bean {
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
MainActivity
package com.example.recyclerview;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private List<Bean> data=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for (int i=0;i<100;i++){
Bean bean=new Bean();
bean.setName("user"+i);
data.add(bean);
}
RecyclerView recycleView= findViewById(R.id.lv);
LinearLayoutManager linearLayoutManager= new LinearLayoutManager(this);
recycleView.setLayoutManager(linearLayoutManager);
MyAdapter myAdapter=new MyAdapter(data,this);
recycleView.setAdapter(myAdapter);
myAdapter.setRecyclerItemClickListener(new MyAdapter.OnRecyclerItemClickListener(){
@Override
public void onRecyclerItemClick(int position) {
Log.e("onclick",""+position);
}
});
}
}
MyAdapter
package com.example.recyclerview;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder>{
private List<Bean> data;
private Context context;
public MyAdapter(List<Bean> data,Context context){
this.data=data;
this.context=context;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view=View.inflate(context,R.layout.list_item,null);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
holder.tv.setText(data.get(position).getName());//将数据绑定到textview
}
@Override
public int getItemCount() {
return data==null?0: data.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
private TextView tv;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
tv=itemView.findViewById(R.id.tv);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(mOnItemClickListener!=null){
mOnItemClickListener.onRecyclerItemClick(getBindingAdapterPosition());
}
}
});
}
}
private OnRecyclerItemClickListener mOnItemClickListener;
public void setRecyclerItemClickListener(OnRecyclerItemClickListener listener){
mOnItemClickListener=listener;
}
public interface OnRecyclerItemClickListener{
void onRecyclerItemClick(int position);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"></androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ddd"
android:height="40dp"/>
</LinearLayout>
启动虚拟器后一直出现以下的状况
Waiting for all target devices to come online,怎么解决
打开任务管理器【ctr+alt+delete】,找到详细信息中的qemu-system关键字眼,右键结束进程
重新按下绿色这个按钮,就行了
我会不定期更新内容哟,很适合像我这样的小白,之前上第一次课的时候,我都快疯了,因为一旦启动内置的虚拟机,你会发现你的电脑会像我的一样(因为我的内存是8G的,所以最好的办法就是将写的放到自己手机运行,哈哈哈哈)注意:安装SDK和模拟机都很慢,要等
更多推荐
所有评论(0)