I basically want to have several views aligned with each other using a relative layout. I can do so using xml, but unfortunately I can't find any documentation that tells me what methods I need to call to get the same effect in code (All the examples and things just use xml). Since the imageviews are being made dynamically xml isn't an option for what I want to do. I've looked at layoutparameters which seems to let me change some options, but I'm not seeing a method that will let me change alignment relative to another view. Any help is appreciated.
After playing around with it some more found that addRule is the method I need. Couldn't find it because I was looking for something with the term alignment in it.
Check out setLayoutParams in the Android documentation:
https://developer.android.com/reference/android/view/View.html#setLayoutParams(android.view.ViewGroup.LayoutParams)
Related
I am starting to delve into Android Development and there is a lot of material online. The question is... What are the pro's and con's against the drag and drop XML design method vs coding the view manually? The only reason I ask on here is because online the views are mixed and they don't really back up what they're defending.
If I use the drag and drop method will I have issues further onto my development adventures? That is the thing that worries me the most... I don't want to learn the drag and drop method and then editting the XML to cater for my needs and then be handicapped by it.
For the beginner(s), I highly recommend not to use Drag and drop. We need to understand XML, to be comfortable with android widget. Understanding XML will come handy in future when creating custom styles and themes.
Here are few pointers before you dive in android XML layout
Try sticking with match_parent and wrap_content while defining android:layout_height or android:layout_width if possible
Make sure you have good understanding of RelativeLayout, LinearLayout and FrameLayout and how its child views are arranged.
Forget about ConstraintLayout, AppbarLayout and similar advance layout at current.
Try exploring TextView, EditText, Button, ImageView and ProressBar as far as possible.(This are most common widgets/views)
Try avoiding any tutorial related to ListView, its deprecated. Try using RecyclerView instead, it is one of the important widget that would be used in regular basis.
I have a xml layout for displaying some results, depending on the result type I need to adjust this view changing 2 textViews and one ImageView, the rest of the layout keeps without changes.
The solution I think is the best is to change the text and the image inside my java code (programmatically).
A friend suggests that is better to make a copy of the entire layout and change this 2 text labels and the image.
IMHO that leads into duplicated code that is why I do not think this is the best option. What do you think is the best approach ? Do you think of a better one?
Thanks in advance.
You are in the right direction. Using 2 different layouts for different results will be absolutely redundant. You can set TextView values by :
textView.setText("Your Text")
and Image resource programatically by:
imageView.setImageResource(R.drawable.yourImage); according to your result.
I have a scrollview with a lot of components in the layout that there is inside it. The result is like that:
I want to know if is there a way to view all components in Android Studio because I need to make changes in the design and currently, by this way it is so difficult.
Thanks for your help.
Set the android:scrollY property on the ScrollView, say 50dp in the beginning and then keep on increasing as you move further down. Make sure you remove this property before production ;)
Did you try to add a new device definition,
Setting it with a bigger height,
And using that one in your preview ?
I've just give it a try and it works nicely !
You should set gone property with for view on top of layout, so you can see view below to edit it.
Let fun with android studio preview!
I currently got this complex screen to implement the XML code.
I suppose to build with the tablelayout, but i still have no idea how to place the item on the shelf and the wooden background behind that. Could anyone hint me some ways ? Thanks
Set the bitmap as your activity's background drawable. From there, you've got several possibilities. Two that should work are
1) Place transparent Button's on the activity, using an AbsoluteLayout.
2) A couple of people have coded solutions similar to the HTML image map construct, and posted them in public fora. Google "imagemap android" and borrow.
Here is a video of my app:
It's currently using absoluteLayout, and since absoluteLayout is deprecated i decided to change my layout.
So what Layout do u suggest using for this app?
Please see the part of the video, that the game has started, that's the only part with absolutelayout.
Thanks
It really depends if you want your UI to flow in a linear fashion or not. The majority of the time I use RelativeLayout with some instances of LinearLayout here and there. Relative seems to me the most flexible for me.
"You can achieve much the same layout by using a FrameLayout instead, and setting layout_margin attributes of the children. This approach is more flexible and will yield better results on different screens."