获取的TextView和ImageView的结束位置相对于屏幕上方相对于、屏幕、位置、结束

由网友(谈情不说爱)分享简介:我有一个位图和它下面是一个时间线。I have a bitmap and below it is a time line.例如,考虑的右侧布局FIGURE.As an example consider the right side layout of the FIGURE.所有底部时限(1,2,3,...)是在...

我有一个位图和它下面是一个时间线。

I have a bitmap and below it is a time line.

例如,考虑的右侧布局FIGURE.

As an example consider the right side layout of the FIGURE.

所有底部时限(1,2,3,...)是在从顶部的高度相同。

All the bottom timelines (1, 2, 3...) are in the same height from top.

时间轴是一个TextView具有固定布局的高度和宽度,因为它是在XML定义 像的时间表1被定义为:

The timeline is a textview which has fixed layout height and width as it is defined in xml like timeline 1 is defined as:

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/HView"
android:layout_marginLeft="18dp"
android:layout_marginTop="345dp"
android:textSize="14sp"
android:text="1"
android:textColor="#000000" />

但是位图的高度和宽度可以变化,因为它是一个编程完成。

However the bitmap height and width can vary as it is done programatically.

因此​​,在某些情况下,则位图的高度增加足以时间轴重叠。换一种说法, 位图的垂直位置提高相对于时间轴的垂直位置。

So in certain cases, the bitmap height increases enough to overlap the timeline. In other words, the vertical position of bitmap increases with respect to the vertical position of the timeline.

我想:

1)位图相对于屏幕的顶部的端垂直位置。

1) the ended vertical position of bitmap with respect to top of the screen.

2)时间表相对于屏幕上方的端垂直位置。

2) the ended vertical position of timeline with respect to top of the screen.

我试着做到以下几点:

TextView bottomTimeLine = (TextView) view.findViewById(R.id.textView1);

bottomTimeLine.getHeight(); //returns 0.

bottomTimeLine.getBottom(); //returns 0.

ImageView img = new ImageView(getActivity());

img.setImageDrawable(getResources().getDrawable(R.drawable.disp_bg));

img.getHeight(); //returns 0.

img.getBottom(); //returns 0.

由于从code看出,这两种方法,的getHeight() getBottom()是返回高度为0。

As seen from the code, both the methods, getHeight() and getBottom() are returning height as 0.

如何获得两者的高度(视图端位置)相对于所述细胞显示的顶部?

How to get the height (view end position) of both with respect to top of the cell display ?

推荐答案

这是它如何可以做到:

final TextView bottomTimeLine = (TextView) view.findViewById(R.id.textView1);

 final int[] timelineCoord = new int[2]; 

 final int[] imgCoord = new int[2]; 



ViewTreeObserver vto = bottomTimeLine.getViewTreeObserver();
 vto.addOnGlobalLayoutListener((new OnGlobalLayoutListener() {

    @Override
    public void onGlobalLayout() {


        bottomTimeLine.getLocationOnScreen(timelineCoord);

    Log.d(" bottomTimeLine H ", ""+timelineCoord[1]);

    timelineHeight = timelineCoord[1];
    }
}));


ViewTreeObserver vt1 = img.getViewTreeObserver();
vt1.addOnGlobalLayoutListener((new OnGlobalLayoutListener() {

    @Override
    public void onGlobalLayout() {


        img.getLocationOnScreen(imgCoord);

        imgHeight = imgCoord[1] + img.getHeight();

    Log.d("Img H ", ""+imgHeight);

if(imgHeight < timelineHeight)
{
int heightDiff = imgHeight - timelineHeight ;

heightDiff = heightDiff + 3;

img.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, heightDiff));
}
    }
}));
阅读全文

相关推荐

最新文章