我知道,RecyclerView已经取代了旧的功能ListView和GridView.我正在寻找一个非常基本的例子,它显示了使用的最小网格设置RecyclerView.我不是在寻找长篇教程风格的解释,只是一个最小的例子.我想最简单的模仿旧GridView的网格将包含以下功能:
我打算开发一个应用程序,在其中显示一些动态数据recyclerCardView.所以我决定
在我的主要内部添加一个recyclerView名字.这是我的应用程序的代码:CheckBoxRecyclerViewrecyclerView
我的主要活动:
setContentView(R.layout.activity_startup);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
reminderView = (RecyclerView) findViewById(R.id.reminder_recycler_view);
RlayoutManager = new LinearLayoutManager(this);
reminderView.setLayoutManager(RlayoutManager);
setSupportActionBar(toolbar);
cardView = (CardView) findViewById(R.id.card_first);
cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext() , ReminderActivity.class);
startActivity(intent);
}
});
ReminderHelper helper = new ReminderHelper(getApplicationContext());
ReminderAdapter reminderAdapter = new ReminderAdapter(helper);
ContentValues reminderValues = new ContentValues();
ContentValues checkboxValues = new ContentValues();
// Devlopment Part ->
reminderValues.put("reminderTitle" , "A Reminder Title");
reminderValues.put("reminderLastModDate" , 0); …Run Code Online (Sandbox Code Playgroud) 如何将当前AttributeSet传递给自定义View类?如果我在参数中使用只有Context的构造函数,我会丢失所有主题,并且能够在xml中为该自定义View使用"style"标记.
我所做的是创建一个活动,其中包含我在xml文件中的自定义视图,然后以编程方式创建一个新的活动并将其添加到布局中.我发现在xml中制作的那个具有适当的样式,而我以编程方式创建的那个没有.
据我所知,两者之间的区别在于系统使用CustomLayout1(Context context, AttributeSet attrs)构造函数.问题是当我以编程方式创建它时,我无法弄清楚如何让应用程序将AttributeSet传递给此自定义视图.
这是活动:
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
public class ThemeOne extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layout = (LinearLayout) findViewById(R.id.mainlayout);
layout.addView(new CustomLayout1(getApplicationContext()));
}
}
Run Code Online (Sandbox Code Playgroud)
这是主要的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/mainlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.clearsync.test.theme1.CustomLayout1 android:id="@+id/maincustom"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
自定义视图类:
import com.clearsync.test.theme1.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
public class CustomLayout1 extends LinearLayout {
private Context context = null;
public CustomLayout1(Context context) { …Run Code Online (Sandbox Code Playgroud) Noob在这里.
我试图在按钮单击上生成图像,为了做到这一点,我从这个问题中获取了一些代码:如何在现有布局中的Java代码中创建ImageView? 我使用了第一个答案中的代码,但是在行中:
RelativeLayout rl = (RelativeLayout) findViewById(R.id.RelativeLayout01);
Run Code Online (Sandbox Code Playgroud)
我不知道要放什么代替"RelativeLayout01",或者如何在"id"中设置布局
提前致谢
我有第一个和第二个布局,我想先插入第二个.我想将第二个布局插入到具有id @ + id/layout的布局中,当我按下按钮获取布局时,它会显示按钮底部的第二个布局
第一个布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btn_get_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Layout" />
<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
第二个布局
<?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:background="@drawable/card_base"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/img_cover"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:scaleType="fitXY"
android:src="@drawable/card_beauty" />
<ImageView
android:id="@+id/img_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="20dp"
android:scaleType="fitXY"
android:src="@drawable/sample_0" />
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 在Android应用程序中使用的布局inflater是什么?
LayoutInflaterAndroid中到底是什么?使用它的目的方法是什么?我可以找到不同类型的用法,但在我的情况下无法找到哪一个套件.
关于这个问题
关于正确使用该inflate()方法,我有很多困惑.在互联网上进行研究时,大多数结果都是错误的或不完整的.即使是官方文件也很模糊.这篇文章是我在不同地方可以找到的内容的总结.我相信这对像我这样的初学者会有所帮助
我在这里看到了许多答案但我实际上无法理解它是什么以及为什么使用它.
有人能给出一点简单的描述来理解它吗?非常感谢