- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
在我的 FragmentLayout
中,我有一个带有多个 subview (TextView
、CardView
)的 LinearLayout
。我想找到所有 LinearLayout
View 的顶部偏移量,但我总是得到零。
这是我的代码:
@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;
}
这是我的布局 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout android:id="@+id/lll">
// views are there
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
最佳答案
在 onWindowFocusChanged(boolean hasFocus)
方法中编写查找位置的函数,或者将任务发布到具有 100 毫秒延迟的处理程序上。
关于android - 为什么 getLocationOnScreen(location) 总是返回 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37790355/
我需要获取应用程序在屏幕上的坐标,以将它们用作弹出窗口的偏移量。 View tempView = (View) findViewById(R.layout.ma
我将以下 3 个包裹在 RelativeLayout 中(忽略 visibility="gone")。 当我调用 view.getLocationOnScreen(pos); 我为 pos[0]
据我所知,当我们将 int[2] 位置数组传递给 view.getLocationOnScreen(location) 时,我们将获得该 View 的左上角坐标。但是当我调试这个函数时,我看到那个位置
我正在使用以下代码获取按钮的位置,但它总是返回零。为什么会这样 Button b=(Button) findViewById(R.id.button2); final int[] x=
我有什么: 具有 android:configChanges="orientation|screenSize|keyboardHidden" 的 Activity 上面有一个 DialogFragme
我在 JButton“支持”上的 ActionListener 中有以下代码。 cl.across.text 是我的 GUI 中的另一个 JTextArea。问题在于点 pt1 给出的结果。 Fram
View.getLocationOnScreen() 返回 View 的 X 和 Y 坐标。 单位是像素还是 DIP? 产地在哪里?左上角? 该位置指的是 View 的哪个角? 轴往哪个方向走?例如3
我调用getLocationOnScreen()来 self 的 Swing 应用程序中的 JFrame。如果 JFrame 最小化为 -32000,则返回 -32000。 预计: Location
我想将 View 的边界投影/转换为屏幕坐标。局部边界是 0,0,1280,628,我 View 正上方的 ActionBar 是 108 像素高。 问题是 view.getLocationOnScr
我试图在 GridLayout 中获取 ImageView 的 x/y,但我的日志一直显示 X & Y: 0 0 有什么想法吗? ... ...
这两种方法的上下文中screen和view有什么区别? 我有一个按钮,我想获取其中心的 x 坐标。 我想这就够了: public int getButtonXPosition() { retu
需要帮助: 我尝试对放置在 FlowLayout 内的每个组件调用 getLocationOnScreen() 并最终获得相同的位置。 这是设计使然还是我做错了什么?那么我应该如何获取每个组件的确切位
我需要获取 JFrame 位置以保存应用程序位置。但问题是 getLocationOnScreen() 返回不正确的结果。或者至少看起来是这样。 public static void main(Str
在响应按钮点击时在 ImageView(或其他 View )上调用 getLocationOnScreen() 会给出正确的值。 但是当从 Activity::onCreate() 调用 getLoc
据我了解,getLocationOnScreen 返回的位置在 Y 轴上从屏幕角的最左上角起增加了状态栏(或操作栏或标题栏?)的高度。 getLocationInWindow 返回 Activity
对 getLocationOnScreen() 或 getLocationInWindow() 的调用都给了我一个 top/Y 坐标约为 30px (status/通知栏的高度)太低了。 left/X
对 Android 很陌生,已经研究了一段时间,但找不到答案。我确信有一个简单的解决方案。 我收到一个 NullPointException,它连接到我的 View characterContaine
在 Android 2.1 模拟器上。 在 ActivityInstrumentationtestCase2 测试类中, 我断言 phototButton 在 sendButton 之上。 @UiTh
在我的 FragmentLayout 中,我有一个带有多个 subview (TextView、CardView)的 LinearLayout。我想找到所有 LinearLayout View 的顶部
我有一个带有 EditText 的 dialog,当用户点击它时,软键盘出现并将 dialog 向上推(以免隐藏)。当键盘关闭时,EditText 恢复其原始位置。这是标准行为。 EditText 明
我是一名优秀的程序员,十分优秀!