I am using the drag and drop feature to add a Linear layout in my activity. when i check the activity_main.xml there is the component created but no "android:id" I cannot manually add the id , because there is no id for this layout in R.java . how to solve it?
The default orientation is horizontal. orientation Pass HORIZONTAL or VERTICAL. Default value is HORIZONTAL.
attributes: android:id. Resource ID. A unique resource name for the element, which you can use to obtain a reference to the View from your application.
android:weightSum. Defines the maximum weight sum. If unspecified, the sum is computed by adding the layout_weight of all of the children. This can be used for instance to give a single child 50% of the total available space by giving it a layout_weight of 0.5 and setting the weightSum to 1.0.
LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.
If you add android:id="@+id/YOUR_ID" to your XML, your IDE (I'm assuming eclipse) will recompile R.java, and you should be able to use R.id.YOUR_ID in your activity.
You needn't use R.id for setting id programmatically. You can use any positive number for id:
myNewLayout.setId(newLayoutIndex);
According to View documentation
The identifier does not have to be unique in this view's hierarchy. The identifier should be a positive number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With