I want to show up a 3*3 grid like matrix view on top of a custom View.(That custom View is used as a view for displaying a ball acting upon the accelerometer). What I wanted to achieve is when the ball on that custom View is acted upon by accelerometer, it would move along the custom View(which I named "mSimulationView"), passing through any one of the 9 grid like boxes. Passing through any of the boxes(grid) triggers a directional control as that of joypad. I want to make the boxes(grid) visible to the users and also change the color of the box(grid) as the ball passes through it.
The problem is I have no idea about how to add the grid view on top of the custom View. If I add "table Rows" or "Grid Views", it would block the custom View completely. I was thinking of using "GLSurfaceView" for this purpose,but I am not sure if that will work or not either. I am trying to make a gravity Simulated Joypad for android.v2.1.
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="250dp"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
</LinearLayout>
I need a 3*3 grid like structure on top of the linearLayout.
Related
What I want to make is that there is two buttons in left side, and imageView on the right side. The buttons activate the camera or bring a photo from the gallery and display it on the imageView. Also, if user touch the image, then a rect shape is following the move of user.
I made a xml file that contain the buttons and imageView.
Then, I made a custom view for the rectangle shape using canvas.
What I was thinking is set touchListener on the imageView and according to the coordinates, app generate the rectangle on the canvas that overlapped on the imageView.
Here is my question, Can I use both a xml file and custom view at the same time? That means those two things can be overlapped?
I tried
v = new DrawingTheBall(this); // v is my custom view
setContentView(v);
setContentView(R.layout.activity_main);
no errors but, only the first called one appears.
If the overlapping is impossible, then should I just put the buttons and imageView in the custom view class?
Yes, you can use layout resource from XML and custom views created programmatically together.
For this you need to:
Specify view holder for custom view in XML and give it an ID (it can be root layout). For example:
<LinearLayout
android:id="#+id/customViewContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
setContentView(R.layout.xml_resource);
Find your custom view container:
LinearLayout custonViewContainer = (LinearLayout)findViewById(R.id.customViewContainer);
Add custom view to container:
custonViewContainer.addView(view);
That's pretty much it!
You can also put your custom view in an XML layout file:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.package.DrawingTheBall
android:id="#+id/drawingTheBall"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
How to make Grid view with click able grid items and nested views (buttons,Image) by remote(For Android TV)
I just want to click able image and button in grid view item should add to play my list if I navigate on button by Remote navigation not by touch
Thank you!!!
How to navigate through d pad in grid view sub items if grid view item have two sub items image button and another button
It is no difference between touch screen or remote control for methods like onClickListener or etc.
For remote control, you need to focus on the element first, than you can click the element.
I have not use the gridView on TV before, but I have used the recyclerView and scrollView. I think they have same situation.
I've try the default simpleAdapter to create the gridView, and it's no problem with the nested views that I can focus and click each grid items after I set the onItemClickListener to the gridView.
I guest your problem is that the grid item conflicts with the button in the grid item.
To avoid this situation, you need to set android:descendantFocusability="blocksDescendants" for the container of your custom grid item view. It will block the items statement in that parent layout.
If you want the button change in the different statement, you can give the button this parameter: android:duplicateParentState="true".
That will let the button follow it's parent's statement.
By the way, don't forget to set some changes to different statement for the grid items (background changes or etc), or you will not know which grid item you have focused :P.
Hope this will help you :)
PS. The following is the sample code for the custom grid item layout. Maybe the example can help you to understand what I mentioned easily.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants" >
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:duplicateParentState="true"/>
</LinearLayout>
2015.01.06 23:11 update:
How to navigate through d pad in grid view sub items if grid view item
have two sub items image button and another button
For this case you should not use OnItemClickListener. Instead, you should make your grid item unfocusable and unclickable, and than set OnClickListener for both two buttons.
You can set the parameters in your customize adapter for the gridView. In getView method you can set each of the grid item view just like convertView.focusable(false) and convertView.clickable(false).
After that, you can set the click listener and give the method you want to do for the buttons in adapter.
Don't care about the D-pad action. Actually, D-pad will work automatically if there are elements can be focused.
The key point for this question is the conflict between grid item and its child elements. You could have just one part to be focused: grid item (the parent view), or the buttons (the child views).
One of the things in android I understand the less, are animations.
It's kinda simple to animate a View, if it's standalone, however, if this animation is for example aligned to the bottom, and an other view is above this view, if you animate the bottom aligned view (move it around the screen), the view which is set to be above never follows this View.
So, is there any way to make "related" views move following the animated view?
Thanks.
If you do need a sample code, I can provide, but I think there's no need to understand.
Sample:
<RelativeLayout ......>
<View
android:id="#+id/topView"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_above="#+id/viewToBeAnimated"/>
<View
android:id="#+id/viewToBeAnimated"
android:layout_width="100dp"
android:layout_height="80dp"
android:alignParentBottom="true"/>
</RelativeLayout>
Now we animate the "view to be animated" to move 25%, for instance to the top. You can see it moving but the topView stand still.
I have an activity with several ListViews in it. I need a rectangle with transparent background that overlaps some of the ListViews and I got lost a little.
I have some drawing coordinates that are known after all views are loaded and I want to put the graphics above the views programmatically.
Should I create a separate view that overlaps the activity window and draw on it or use the existing views? How do I start?
You can just add this in your layout xml:
<View android:id="#+id/view"
android:layout_width="300dp"
android:layout_height="300dp"
android:background="#android:color/transparent"/>
if you want views to overlaps another views use relative layout and build it correctly.
I have a RelativeLayout that holds a set of views and i would like that one of the views will
appear in front of all the other views? how can i do that ?
Thanks
EDIT :
OK, i will be more specific.
here is the code of my relativelayout, this is where i put all of my view.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cfff"
android:id="#+id/myMap">
i'm adding view to this relativelayout this way :
creating different views......
relativelayout.addView(view);
now, some of the view intersect with each other and when this happens i want to control which view will be on top of the other one. so how can i do that ?
Thanks.
The view will be ordered on the Z-axis in the order that they are added. So the first view will be the further in your layout. The next view added will be on top of the first view and so on.