我创建了一个自定义视图,并在其上放置了大约14 EditText
。我想更改EditText
之一的位置,因此首先我使用了editText.bringToFront();
,然后我使用此EditText
getChildAt(childIndex).setY(y);
的索引更改了此按钮的位置。当我看到他们的索引高于此按钮的所有EditTexts
正在移动时,我感到很惊讶。我不知道为什么bringToFront
方法会更改其他EditTexts
的索引。
使用Button
(非EditText
)的简化源代码。这可以在没有bringToFront()
的情况下正常工作。但我想使用EditText
:
public class CustomView extends ViewGroup{
private int height;
private int childCount;
int chosenIndex;
public CustomView(Context context) {
super(context);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
childCount = getChildCount();
height = 200;
for (int childIndex = 0; childIndex < childCount; childIndex++) {
Button child = (Button) getChildAt(childIndex);
child.layout(l, childIndex * height, r, (childIndex + 1) * height);
child.setText("" + childIndex);
}
}
public boolean onInterceptTouchEvent(MotionEvent ev) {
super.onInterceptTouchEvent(ev);
float y = ev.getY();
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
for (int i = 0; i < childCount; i++) {
if (getChildAt(i).getY() < y && getChildAt(i).getY() + getChildAt(i).getHeight() > y) {
chosenIndex = i;
}
}
break;
case MotionEvent.ACTION_MOVE:
// No bringToFront()
getChildAt(chosenIndex).setY(y);
break;
case MotionEvent.ACTION_UP:
getChildAt(chosenIndex).setY(y);
break;
}
return false;
}
}
包含EditText
的源代码(问题在这里,这不适用于bringToFront()
或没有它)
public class CustomView extends ViewGroup{
private int height;
private int childCount;
int chosenIndex;
public CustomView(Context context) {
super(context);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
childCount = getChildCount();
height = 200;
for (int childIndex = 0; childIndex < childCount; childIndex++) {
EditText child = (EditText) getChildAt(childIndex);
child.layout(l, childIndex * height, r, (childIndex + 1) * height);
int color = Color.rgb(childIndex * 40, 0, 0);
child.setBackgroundColor(color);
child.setText("" + childIndex);
}
}
public boolean onInterceptTouchEvent(MotionEvent ev) {
super.onInterceptTouchEvent(ev);
float y = ev.getY();
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
for (int i = 0; i < childCount; i++) {
if (getChildAt(i).getY() < y && getChildAt(i).getY() + getChildAt(i).getHeight() > y) {
chosenIndex = i;
}
}
break;
case MotionEvent.ACTION_MOVE:
getChildAt(chosenIndex).bringToFront(); // Here is the problem with BringToFront
getChildAt(chosenIndex).setY(y);
break;
case MotionEvent.ACTION_UP:
getChildAt(chosenIndex).setY(y);
break;
}
return false;
}
}
答案 0 :(得分:1)
问题可能是由于$settings = Settings::instance();
$this->ogFbAdmins = $settings->str_og_fb_admins;
foreach ($this->ogFbAdmins as $adm) {
echo $adm->str_og_fb_admins;
}
参数(它出现在&gt; = elevation
版本上)。
试试这个:
Lollipop
ViewCompat.setElevation(btn, 0);
Buttons
移到其他人之上时,不仅而是也 btn.bringToFront()
。