viewgroup

How to use addView to add view to layout?

妖精的绣舞 提交于 2020-04-08 19:03:19
问题 I have read probably all posts and documentation but I still can't solve this issue. I want to use addView() method to add view to the existing (running) layout but for some reason I cant. I know that this should be easy and basic but still I cant do it. So, please help me. Here is a code: LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout); TextView text = new TextView(this); text.setText("test"); layout.addView(text); That's a code, and the result is that I have displayed only

How to use addView to add view to layout?

ぃ、小莉子 提交于 2020-04-08 19:01:38
问题 I have read probably all posts and documentation but I still can't solve this issue. I want to use addView() method to add view to the existing (running) layout but for some reason I cant. I know that this should be easy and basic but still I cant do it. So, please help me. Here is a code: LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout); TextView text = new TextView(this); text.setText("test"); layout.addView(text); That's a code, and the result is that I have displayed only

自定义组件之规则分布按钮的菜单

北城以北 提交于 2020-03-16 14:21:26
某厂面试归来,发现自己落伍了!>>> 废话不多说,先上效果图(下了几个屏幕录制软件,效果不是很好,只能截取部分图片了,各位有什么好用的推荐下): 图中间的圆形布局菜单是一个继承ViewGroup的组件,可以动态添加外围菜单按钮个数,会自动围绕中间按钮形成一个圆圈。不过外围的按钮不要太多,不然会重叠,而且太多也不好看。 主要思路就是重写ViewGroup的onMeasure()和onLayout()这两个方法。其中onMeasure()用来计算组件所需的区域大小,可以根据实际需要进行计算。onLayout()方法中根据需求摆放你的childView。 接下来,重点讲下如何计算组件的大小。首先,组件区域肯定是一块矩形区域,本组件刚好是一个正方形。所有外围childView围成的圆是这个正方形区域的内接圆。假设这个正方形区域的宽和高分别为Width和Height,中心圆的半径为centerR,外围圆的半径为outsideR,中心圆和外围圆之间间隔Dur,以外围childView围成的圆半径为R。那么 Width = Height = (centerR/2 + outsideR + Dur)*2; R = centerR/2 + outsideR/2 + Dur; 正方形区域的算法就这么简单。但是,在 onMeasure()方法中,有一个东东一定要会用,那就是MeasureSpec

Android transfer animation of view in custom viewgroup

ⅰ亾dé卋堺 提交于 2020-02-29 07:03:07
问题 I want animation like expanding of the photos when I click folder of photos at gallery, like in this video about Android gallery. i have two views in same custom viewgroup view1 is in 0,0 view2 is in 100,100 since click "start" view1 will move to 100,0 and view2 will move to 0,100 My solution so far: I use timer for refresh layout with new position by requestlayout. the views' position will refresh by onLayout : It works but it's not a native function and it is very slow with 100 views moving

Animate viewgroup without animating children

亡梦爱人 提交于 2020-01-14 03:11:47
问题 i have built a custom viewgroup and m beginning to implement animations tot his viewgroup. the problem i am having is that i need the viewgroup to be able to animate without it's children being animated by the same animation. Lets say i am scaling the viewgroup to 2x size, but i still want to keep children at the same size (thus fitting more children into the viewgroup). Right now i am calling the animation as follows: ScaleAnimation expandAnimation = new ScaleAnimation(1,2,1,2); this

Draw bitmaps on top of the Navigation bar in Android

一世执手 提交于 2020-01-11 03:33:06
问题 In my application, I need to draw a bitmap on top of all the apps running. I created a view which is invisible and overlays on top of all the apps. with this overlay view I can draw bitmaps at the given position , But I am unable to draw the bitmap on top of the Navigation Bar.I used the following layout parameters. WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_FULLSCREEN |WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |WindowManager.LayoutParams.FLAG_NOT

Android onInterceptTouchEvent, get childs in ViewGroup

大憨熊 提交于 2020-01-06 06:40:31
问题 I have a layout(like board) like this that contains cells(buttons) | A | B | C | D | ----------------- | E | F | G | H | ----------------- | I | J | K | L | ----------------- | X | Y | Z | W | I'm adding Cells programmatically, they contains letters I set. public void addCells(String letters){ removeAllViews(); int let = 0; for (int j = 0; j < 4; j++){ for (int i = 0; i < 4; i++){ String currentLetter = ""+letters.charAt(let); //Cell object that contains it's position and letter. Cell cell_ =

force onLayout in a subView whose dimensions doesn't change

醉酒当歌 提交于 2020-01-03 13:02:49
问题 I have a Custom ViewGroup with some views inside. In response to an event, a requestLayout is called and in OnLayout some of the views will get a new layout position. One of them maintain its position but needs to be rearranged inside. However this view's onlayout method will not be called since its layout position doesn't change. Trying to call requestLayout , forceLayout or invalidate in this view doesn't work. The only dirty trick that I have found is to change some of its value position

force onLayout in a subView whose dimensions doesn't change

不打扰是莪最后的温柔 提交于 2020-01-03 13:00:11
问题 I have a Custom ViewGroup with some views inside. In response to an event, a requestLayout is called and in OnLayout some of the views will get a new layout position. One of them maintain its position but needs to be rearranged inside. However this view's onlayout method will not be called since its layout position doesn't change. Trying to call requestLayout , forceLayout or invalidate in this view doesn't work. The only dirty trick that I have found is to change some of its value position

How to use Scroller in ViewGroup (android)

自闭症网瘾萝莉.ら 提交于 2020-01-02 09:57:45
问题 I have a custom ViewGroup and would like to add scrolling ability to it. Is it possible to use a Scroller object and link it up with view group? I have read somewhere that Scroller does not do any actual scrolling. That means it must be delegating the scrolling responsibility back to ViewGroup. thanks 回答1: The ScrollView object is what allows for scrolling. Basically, most Views are able to be scrolled, but they have no way of propagating touch events to the View class. A ScrollView handles