relativelayout

How to place views in a specific location (x, y coordinates)

心已入冬 提交于 2019-11-28 11:44:41
I have a problem with placing my views (my class extends View ) in a specific location. I have designed a game that treats the screen as a net of grids. I get from the user x and y coordinates of a specific view (I have different types of views). My first mission is to set the correct view in its place. How can I do it? I am using RelativeLayout for the screen. P.S. I don't want to use AbsoluteLayout params because it was truncated. wsgfz This is not the best way to achieve it, but it's a solution... Create a class that extends your parent ViewGroup , say RelativeLayout or some other ViewGroup

Xamarin.Forms: How to center views using Relative Layout? `Width` and `Height` return -1

橙三吉。 提交于 2019-11-28 10:15:53
When trying to use the Height and Width properties of a control in Xamarin.Forms, both return -1, and it causes the Relative Layout to appear off-centered on the screen. var mainLayout = new RelativeLayout(); //Add the Switch to the center of the screen mainLayout.Children.Add(mySwitch, Constraint.RelativeToParent(parent => parent.Width / 2 - mySwitch.Width / 2), Constraint.RelativeToParent(parent => parent.Height / 2 - mySwitch.Height / 2)); //Add a Label below the switch mainLayout.Children.Add(switchLabel, Constraint.RelativeToParent(parent => parent.Width / 2 - switchLabel.Width / 2),

Android - set layout background programmatically

让人想犯罪 __ 提交于 2019-11-28 09:19:05
I have noticed that the setBackground method for the RelativeLayout object is targeted for API 16 (Android 4.1) and higher, but my application has the target API 8 and I cannot use it. Is there any alternative solution for this problem (besides marking the class/method with TargetApi (16) or changing the target API in the manifest)? Thank you! Edit : Eclipse was buggy and it showed me the same error for setBackgroundDrawable but now it seems to work. Thank you for your help. Eric Use one of: .setBackgroundColor(int) (if you're setting it to a color) .setBackgroundDrawable(Drawable) (if you're

How to have a fixed footer with scrollview in android?

☆樱花仙子☆ 提交于 2019-11-28 07:05:11
I have been trying to use Fixed footer not displaying the bottom-most list item but does not work with scrollview . Note i am not using listview but it is a big layouts with images and buttons . The footer should be positioned at the botton always even while user is scrolling . FourSquare has this in their app where there is fixed footer even while scrolling. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" > <RelativeLayout android:id="@+id/root" android:layout_width="wrap

How to design spannable gridview using recyclerview (SpannableGridLayoutManager)

旧城冷巷雨未停 提交于 2019-11-28 06:18:22
问题 I want to design grid view like below image provided. The first item should be bigger than the rest. Currently I am using RelativeLayout with GridLayoutManager check below code RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view1); RecyclerView.LayoutManager recyclerViewLayoutManager = new GridLayoutManager(context, 3); recyclerView.setLayoutManager(recyclerViewLayoutManager); recyclerView_Adapter = new RecyclerViewAdapter(context,numbers); recyclerView.setAdapter

Relative Layout get Width/Height return 0

感情迁移 提交于 2019-11-28 04:19:48
问题 I need to get width and height of Relative layout, however I do not know when the Relative Layout is ready to provide me these two attributes. My activity has several tabs and I call the getWidth() and getHeight() in onCreateView() after inflater.inflate(R.layout.fragment_pizza, container, false); , however it returns 0 for both of them, so they are not apparently ready. Is there some kind of event like afterCreateView() or something similar where I can call these two methods and get the

ArrayAdapter requires ID to be a TextView error

﹥>﹥吖頭↗ 提交于 2019-11-28 02:05:50
I am trying to create a nice layout for my list items, but my code only works when it is simplified like this: <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:textSize="16sp" > </TextView> When I add a little bit more it compiles and runs but it force closes on start and gives me the error ArrayAdapter requires ID to be a TextView : <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill

layout with buttons in a circle?

泄露秘密 提交于 2019-11-28 02:00:35
问题 Its a challenge for all.. How we can put buttons in relative or linear layout or any other layout in a circle same as in this image. We can do it using xml or using code. Please help. Thanks in advance 回答1: This method is the layout equivalent of plotting arbitrary X and Y coordinates. Features: The child objects are automatically centered in the RelativeLayout whether you use it as the top-level layout or embed it in another. For N images your layout contains only N+1 views. This example

Android ScrollView not working properly

冷暖自知 提交于 2019-11-28 01:02:19
问题 I developed an android application in which the scroll-view is not scrolling.. I am posting the code here pls check and if found any error pls help.. Here I used Linear Layout as root and then Scroll-view and Relative Layout inside the scroll-view and ... text-views inside relative layout... but this is not scrolling up.. XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height=

Android nested layouts

限于喜欢 提交于 2019-11-28 00:34:24
问题 I am new to android layouts, Could please tell me how the performance of application when using nested layouts instead of using layout below, layout above, layout right, layout left attributes of relative layout for components. For eg: <RelativeLayout> <scrollView> <RelativeLayout> <LinearLayout> Header<LinearLayout> <TextView/> <TextView/> <TableLayout> <TableRow><ImageView/> <TextView> <Spinner><TableRow> <TableRow><ImageView/> <TextView> <Spinner><TableRow> <TableRow><ImageView/> <TextView