android-relativelayout

Differences between ConstraintLayout and RelativeLayout

夙愿已清 提交于 2019-11-26 03:47:47
问题 I am confused about the difference between ConstraintLayout and RelativeLayout . Could someone please tell me the exact differences between them? 回答1: Intention of ConstraintLayout is to optimize and flatten the view hierarchy of your layouts by applying some rules to each view to avoid nesting. Rules remind you of RelativeLayout , for example setting the left to the left of some other view. app:layout_constraintBottom_toBottomOf="@+id/view1" Unlike RelativeLayout , ConstraintLayout offers

How to set RelativeLayout layout params in code not in xml?

隐身守侯 提交于 2019-11-26 03:35:49
问题 For example I want to add 3 buttons on screen: one align left, one align center, last one align right. How can I set their layout in code, not in xml ? 回答1: Just a basic example: RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); Button button1; button1.setLayoutParams(params); params = new RelativeLayout.LayoutParams

Is a RelativeLayout more expensive than a LinearLayout?

风格不统一 提交于 2019-11-26 02:18:26
问题 I\'ve always been using RelativeLayout everytime I needed a View container, because of it\'s flexibility, even if I just wanted to display something really simple. Is it ok to do so, or should I try using a LinearLayout when I can, from a performance/good practices standpoint? Thanks! 回答1: In a talk at Google I/O 2013 (Writing Custom Views for Android), Romain Guy clarified the misunderstanding that caused everyone to start using RelativeLayouts for everything. A RelativeLayout always has to

Percentage width in a RelativeLayout

我与影子孤独终老i 提交于 2019-11-26 00:17:20
问题 I am working on a form layout for a Login Activity in my Android App. The image below is how I want it to look like: I was able to achieve this layout with the following XML . The problem is, it\'s a bit hackish. I had to hard-code a width for the host EditText. Specifically, I had to specify: android:layout_width=\"172dp\" I\'d really like to give a percentage width to the host and port EditText\'s . (Something like 80% for the host, 20% for the port.) Is this possible? The following XML

How to lay out Views in RelativeLayout programmatically?

懵懂的女人 提交于 2019-11-25 23:43:40
问题 I\'m trying to achieve the following programmatically (rather than declaratively via XML): <RelativeLayout...> <TextView ... android:id=\"@+id/label1\" /> <TextView ... android:id=\"@+id/label2\" android:layout_below: \"@id/label1\" /> </RelativeLayout> In other words, how do I make the second TextView appear below the first one, but I want to do it in code: RelativeLayout layout = new RelativeLayout(this); TextView label1 = new TextView(this); TextView label2 = new TextView(this); ... layout