viewgroup

How to initialize Container(ViewGroup)?

こ雲淡風輕ζ 提交于 2019-12-08 07:47:13
问题 Automatically, in OnCreateView, there's: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { I want to initialize my variable as in the same way like OnCreateView in AsyncTask. I was able to initialize these variable : LayoutInflater inflater; ViewGroup container; inflater = (LayoutInflater) ctx .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rootView = inflater.inflate(R.layout.fragment_pager_list, container, false); However,

Animate viewgroup without animating children

我与影子孤独终老i 提交于 2019-12-08 04:12:25
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.startAnimation(expandAnimation); Thanks in advance! :) You can't directly do what you're seeking to do with

Android onInterceptTouchEvent 和 onTouchEvent

风流意气都作罢 提交于 2019-12-07 17:24:57
o nInterceptTouchEvent 方法是ViewGroup的方法,也就是所有的容器都将继承该方法。此方法设计的意图是为了在父容器将touch事件传递给子控件的时候可以统一控制。比如button就没有该方法,很明显,button不可能拥有子控件。 onTouchEvent 方法是 view 的方法,当该控件接收到 touch 事件时,此方法会被执行。每一个 touch 事件总是从 ACTION_DOWN 事件开始, ACTION_UP 结束。 Touchevent 中,返回值是 true ,则说明消耗掉了这个事件,返回值是 false ,则没有消耗掉,会继续传递下去 Touch 事件几大原则: 1. 如果在某个层级没有处理 ACTION_DOWN 事件,那么该层就再也收不到后续的 Touch 事件了直到下一次 ACTION_DOWN 事件。 说明: a. 某个层级没有处理某个事件指的是它以及它的子 View 都没有处理该事件。 b. 这条规则不适用于 Activity 层(它是顶层),它们可以收到每一个 Touch 事件。 c. 如果没有处理 ACTION_MOVE 这类事件,不会有任何影响。 2. 如果 ACTION_DOWN 事件发生在某个 View 的范围之内,则后续的 ACTION_MOVE , ACTION_UP 和 ACTION_CANCEL

自定义ViewGroup (3) 与子View之间 Touch Event的拦截与处理

情到浓时终转凉″ 提交于 2019-12-07 04:07:04
在昨天的博客( 自定义ViewGroup(2) )中,我们解决了多个手指交替滑动带来的页面的跳动问题。但同时也还遗留了两个问题。 我们自定义的这个ViewGroup本身还不支持onClick, onLongClick事件。 当我们给子View设置click事件后,我们的ViewGroup居然不能滑动了。 相对来讲,第一个问题稍稍容易处理一点,这里我们先说一下第二个问题。 onInterceptTouchEvent()的作用以及何时会被调用 onInterceptTouchEvent()是用来给ViewGroup自己一个拦截事件的机会,当ViewGroup意识到某个Touch事件应该由自己处理,那么就可以通过此方法来阻止事件被分发到子View中。 为什么onInterceptTouchEvent()方法只接收到来ACTION_DOWN事件??需要处理ACTION_MOVE,ACTION_UP等等事件吗?? 按照google官方文档的说明: 如果onInterceptTouchEvent方法返回true,那么它将不会收到后续事件,事件将会直接传递给目标的onTouchEvent方法(其实会先传给目标的onTouch方法) 如果onInterceptTouchEvent方法返回false,那么所有的后续事件都会先传给onInterceptTouchEvent

Android: Using FEATURE_NO_TITLE with custom ViewGroup leaves space on top of the window

泪湿孤枕 提交于 2019-12-07 02:36:47
问题 I am trying to create a custom ViewGroup, and I want to use it with a full screen application. I am using the "requestWindowFeature(Window.FEATURE_NO_TITLE)" to hide the title bar. The title bar is not showing, but it still consuming space on top of the window. The image above was generated with the following code: public class CustomLayoutTestActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window

Custom ViewGroup focus handling

爱⌒轻易说出口 提交于 2019-12-06 17:02:39
问题 Let's say I have a custom ViewGroup which is focusable and has some child views which are focusable as well (A custom vertical menu for Android set-top-boxes which should react on remote controller). I need to pass a focus to some of the child views whenever the custom ViewGroup gains the focus. I set descendantFocusability to beforeDescendants and set OnFocusChangeListener to the custom ViewGroup but OnFocusChangeListener.onFocusChanged() is never called. It looks like beforeDescendants does

How to use Scroller in ViewGroup (android)

社会主义新天地 提交于 2019-12-06 08:14:51
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 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 this for the user, so should be wrapped around a View whenever you would like to enable Scrolling for a that

Android 自定义View实现画背景和前景(ViewGroup篇)

空扰寡人 提交于 2019-12-06 07:09:16
在定义ListView的Selector时候,有个drawSelectorOnTop的属性,如果drawSelectorOnTop为true的话,Selector的效果是画在List Item的上面(Selector是盖住了ListView的文字或者图片),即Foreground前景。如果drawSelectorOnTop为false的话,Selector的效果是画在List Item的下面,即Background背景。由于项目中恰好需要自定义View,需要实现此效果。 本文借ListView的代码来剖析一下, ListView完成此部分功能在frameworks\base\core\java\android\widget\AbsListView.java文件中。 用mSelector即ListView要画的Selector(资源文件),而mSelectorRect则是想要画的区域。 /** * Indicates whether the list selector should be drawn on top of the children or behind */ boolean mDrawSelectorOnTop = false; 决定画前景还是背景 /** * The drawable used to draw the selector */ Drawable

Android - do ViewGroup onDraw need to iterate through child view and call onDraw explicitly?

送分小仙女□ 提交于 2019-12-06 05:51:21
I have spent the whole day debugging various ways to add custom ViewGroup into another custom ViewGroup and nearly went crazy because none of them works, and there is no official documentation or sample that shows how it can be done... Basically, I have 2 custom ViewGroup : HorizontalDockView extends ViewGroup GameEntryView extends FrameLayout HorizontalDockView overrides onDraw , onMeasure , etc and everything is called normally and works perfectly. However, when I create GameEntryView from inside HorizontalDockView 's constructor and call addView(gameEntryView) , the gameEntryView will never

Android: using MotionEvent to do drag and drop positioning of Views in a custom ViewGroup

元气小坏坏 提交于 2019-12-06 04:37:21
问题 I am having trouble positioning view elements on a custom ViewGroup that I have created, specifically in drag-and-drop situations. I am targeting Android 2.2 and up, so I can't really use the drag-and-drop API that came into existence in Android 3. My custom ViewGroup is called "NodeGrid" and it extends "RelativeLayout". Its onLayout method is overriden such that it looks like this: @Override protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) { //pxConversion is a