LayoutInflater在Android中有什么用?
Android项目的build.gradle中buildtoolsVersionvs 之间有什么区别compileSdkVersion?
编辑:具体来说,我想澄清构建工具是什么?
我有一个带有GridLayoutManager的RecyclerView,可以显示卡片视图.我希望卡片根据屏幕尺寸重新排列(Google Play应用程序使用其应用程序卡执行此类操作).这是一个例子:
以下是我的应用程序当前的样子:
正如您所看到的那样,这些卡片只是拉伸而不适合从方向更改所形成的空白区域.那我该怎么做呢?
码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Json;
using System.Threading;
using System.Threading.Tasks;
using Android.Media;
using Android.App;
using Android.Support.V4.App;
using Android.Support.V4.Content.Res;
using Android.Support.V4.Widget;
using Android.Support.V7.Widget;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Android.Net;
using Android.Views.Animations;
using Android.Graphics;
using Android.Graphics.Drawables;
using Newtonsoft.Json;
using *******.Adapters;
using *******.Models;
namespace *******.Fragments {
public class Dashboard : GridLayoutBase {
private ISharedPreferences pref;
private SessionManager session;
private string cookie;
private DeviceModel deviceModel;
private RecyclerView …Run Code Online (Sandbox Code Playgroud) layout android xamarin android-gridlayout android-recyclerview
在GitHub的一个简单的应用程序项目中,我只有2个自定义Java文件:
Adapter并ViewHolder用于显示蓝牙设备RecyclerView当用户点击蓝牙设备时,MainActivity.java包含一个要调用的方法RecyclerView:
public void confirmConnection(String address) {
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Do you want to pair to " + device + "?");
builder.setPositiveButton(R.string.button_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
device.createBond();
}
});
builder.setNegativeButton(R.string.button_cancel, null);
builder.show();
}
Run Code Online (Sandbox Code Playgroud)
在ViewHolder类(在DeviceListAdapter.java中)中定义了单击侦听器:
public class DeviceListAdapter extends
RecyclerView.Adapter<DeviceListAdapter.ViewHolder> {
private ArrayList<BluetoothDevice> mDevices = new ArrayList<BluetoothDevice>();
protected static …Run Code Online (Sandbox Code Playgroud) android android-bluetooth android-viewholder android-recyclerview
我正在制作9x9数独网格,其中81个单元格中的每个单元本身都是3x3网格。一个单元格看起来像这样:
1 2 3
4 5 6
7 8 9
每个数字代表该单元格的铅笔注释。我有一个名为cell_layout.xml的文件,表示此3x3排列。
我已经能够生成网格,并且代码有效:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.solver_principal);
TableLayout sudokuGrid = (TableLayout) findViewById(R.id.sudokuGrid);
sudokuGrid.setShrinkAllColumns(true);
sudokuGrid.setStretchAllColumns(true);
TableRow.LayoutParams paramsRow = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
TableLayout.LayoutParams paramsLayout = new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT);
for(int i = 0; i < 9; ++i)
{
TableRow tableRow = new TableRow(SolverActivity.this);
tableRow.setDividerDrawable(getResources().getDrawable(R.drawable.column_divider));
tableRow.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
for(int j = 0; j < 9; ++j)
{
View cell = getLayoutInflater().inflate(R.layout.cell_layout, sudokuGrid, false);
cell.setLayoutParams(paramsRow);
tableRow.addView(cell);
}
tableRow.setLayoutParams(paramsLayout);
sudokuGrid.addView(tableRow);
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码仅将所需布局放大81倍到TableLayout中。
它有效,那么您的问题是什么?
该活动创建时间过长。即使我仅用网格的一行进行测试,该方法仍需要花费很长时间才能膨胀多次所需的布局。 …