是否有一个具体的项目移动到特定位置的方式RecyclerView使用LinearLayoutManager编程方式?
在下面的代码中,我需要检查一个数字是否在ArrayList. 用户输入一个号码进行查询,如果存在array且不止一个则显示“出现不止一次”。我一直在尝试这样做,但我不知道该怎么做。
这是main课程:
ArrayList<Integer> list = new ArrayList<>();
list.add(3);
list.add(2);
list.add(7);
list.add(2);
System.out.println("Type a number: ");
int number = Integer.parseInt(sc.nextLine());
if (Metodos.moreThanOne(list, number)) {
System.out.println(number + " appears more than once.");
} else {
System.out.println(number + " does not appear more than once.");
}
Run Code Online (Sandbox Code Playgroud)
这是方法:
public static boolean moreThanOne(ArrayList<Integer> list, int number) {
for (Integer in : list) {
if (list.contains(number) && in==in) {
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud) 在a中RecyclerView,我试图获得点击项目的X和Y位置.这是在我的适配器内:
@Override
public void onBindViewHolder(AlfabetoViewHolder holder, final int position) {
// setImage(holder.imageButton, images.get(position));
holder.imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
view.getX(); // This is 0, but it shouldn't be!
view.getY(); // This is also 0.
executaSomAnimacaoLetra(sounds.get(position), Utils.getResourceFromFile(popups.get(position), context), view); // I do some stuff here
}
});
}
Run Code Online (Sandbox Code Playgroud)
事实是,X和Y都总是返回0,他们不应该.我需要点击项目的X和Y来做一些动画.
我已经尝试将X和Y位置放在一个内部和一个OnGlobalLayoutListener内部OnPreDrawListener(当你需要活动的onCreate上的X和Y时它们都工作),但它们也返回0.
我正在使用GridLayoutManager我的RecyclerView:
recyclerView.setLayoutManager(new GridLayoutManager(Activity_alfabeto.this, 7, LinearLayoutManager.VERTICAL, false));
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.
在我的FragmentLayout我LinearLayout有多个子视图(TextView,CardView)。我想找到所有LinearLayout视图的顶部偏移量,但我总是得到零。
这是我的代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_detail, container, false);
nestedScrollView = (NestedScrollView) view.findViewById(R.id.nestedScrollView);
linearLayout = (LinearLayout) view.findViewById(R.id.lll);
int childCount = linearLayout.getChildCount();
int[] location = new int[2];
for (int i = 0; i < childCount; i++) {
View v = linearLayout.getChildAt(i);
v.getLocationOnScreen(location);
Log.e("locX", location[0] + "");
Log.e("locY", location[1] + "");
}
return view;
}
Run Code Online (Sandbox Code Playgroud)
这是我的布局 xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"> …Run Code Online (Sandbox Code Playgroud) 如何使用JavaFX创建三角形?我已经尝试过这些,但是我不知道如何正确地解决它:
Polygon triangle = new Polygon();
triangle.getPoints().setAll(
50, 50,
60, 60,
20, 40
);
Run Code Online (Sandbox Code Playgroud) 我想编写一个简单的程序,要求您通过键盘输入数字(每个数字用空格或逗号分隔),然后将它们从低到高排序.
我想到的是要求用户通过键盘输入数字,将输入设置为String对象,然后通过for循环传递String,确定字符是数字还是普通字符.如果caracter是一个数字,它将附加到一个String数组的字段并查找下一个数字并执行相同的操作,直到一个字符不是数字; 在这种情况下,它会查找另一个数字并重复相同的过程,但使用下一个String数组的字段.一旦程序通过了String String的长度,String Array的每个字段都将转换为int,因此可以对其进行排序.
问题是我不知道如何将未定义数量的字符添加到a String.我所做的是以下内容:
public class StartHere {
public static void main(String[] args) {
int[] numbers;
String input;
boolean fieldUsed = false;
int len = 0;
Scanner scanner = new Scanner(System.in);
input = scanner.next();
numbers = new int[input.length()];
String[] aux = new String[input.length()];
int numOfAuxField = 0;
for (int i = 0; i < input.length(); i++) {
do{
if(Character.isDigit(input.charAt(i))){
aux[numOfAuxField].append((input.charAt(i)).toString());
i++;
fieldUsed = true;
}else{
if(fieldUsed == true){
numOfAuxField++;
}
} while(Character.isDigit(input.charAt(i)));
}
for (int a …Run Code Online (Sandbox Code Playgroud) 我ImageView想在其中一张一张地显示两张图像。我希望这两个图像之间的过渡具有淡入淡出效果。这是我尝试过的:
KeyFrame keyFrame1On = new KeyFrame(Duration.seconds(.2), new KeyValue(imageView.imageProperty(), image1, Interpolator.EASE_OUT));
KeyFrame keyFrame2On = new KeyFrame(Duration.seconds(.5), new KeyValue(imageView.imageProperty(), image2, Interpolator.EASE_OUT));
Timeline timelineOn = new Timeline(keyFrame1On, keyFrame2On);
timelineOn.setAutoReverse(false);
timelineOn.play();
Run Code Online (Sandbox Code Playgroud)
但图像之间的过渡是坚实的,没有褪色。我究竟做错了什么?
我已经实现了CardView使用代码RecyclerView.我的清单有15个项目,现在我想更改CardView列表中的每个奇怪的背景颜色.请为我提供正确的代码CardView.我尝试过简单的奇数偶数代码.这是代码:
在onBindViewHolder方法中:
@Override
public void onBindViewHolder(final DataHolder holder, int position) {
holder.tv1.setText(result[position]);
imageLoader.displayImage("drawable://" + imgs[position], holder.iv1, options);
for(int i =0; i <= imgs.length;i+=2)
{
holder.cv1.setCardBackgroundColor(R.color.colorAccent);
}
}
Run Code Online (Sandbox Code Playgroud) 我试图制作一个代码来回答另一个人的问题......我出现了另一个问题.
这个想法是一个程序,要求你输入数字,以便对它们进行排序并从高到低打印出来.
这就是我的意思:
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Input: ");
Integer input = new Integer(Integer.parseInt(scanner.nextLine()));
scanner.close();
Integer[] numbers = new Integer[input.toString().length()];
for (Integer value : numbers) {
while (input > 1) {
value = input % 10;
input /= 10;
}
}
Arrays.sort(numbers, Collections.reverseOrder());
int a = 0;
for (Integer value : numbers) {
if (a < numbers.toString().length()) {
System.out.print(value + ", ");
a++;
} else {
System.out.println(value + ".");
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,作为 …