Linear Layout Or Relative Layout? [closed] - android

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
someone said people must use relative layout when make android app. Because if use linear layout, app's screen doesn't adjust device screen. (I mean width and height doesn't adjust). But if I use relative layout, it's make me annoyed when I set image. Is opinion which I hear right ?

In my view i would prefer RelativeLayout as parent.
And i go for LinearLayout for all the inner layouts where i can use
android:orientation and android:height as match_parent/fill_parent that will fill only the space available with in LinearLayout.
I never prefer to use dp values for android:height and android:width

I'll go with Relative Layout as we can set different views easily in this layout.

Both have it's own pros and cons. Both can adjust without any problem to device screen. What really matter are the views that you will put inside of them (children) and how they will be organized.
In addition to that, you may want to modify the gravity, margin, padding, alignment or any other to achieve a desired result.

Related

how to auto expand the height of TextView when text line/material is large [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am working on an app and i am facing a problem about height of text view w.r.t text data.
i explain my problem with an example,
Suppose i have data like that:
String data = "In India in 1987, Khan led Pakistan in its first-ever Test series win and this was followed by Pakistan's first series victory."
and this data can easily be fit textview. But if the size of data become large like
String data = "In India in 1987, Khan led Pakistan in its first-ever Test series win and this was followed by Pakistan's first series victory,Khan led Pakistan in its first-ever Test series win and this was followed by Pakistan's first series victory."
Then is that case, the remaining part of data is not shown within the height of textView.
My question is how to dynamically increase the height of textivew for large data keeping in mind the following requirements
Text size is fixed e.g "14dp"
only size/height of textView should be increased
I have not to use the scroll view for large data, i only want to use scroll view when the size of data (eventually TextView) become large enough the size of screen, then i want to use scrollView only, to vertically scroll.
Can any one give the good solution, for this described problem. please share some snipt of code for my better understanding. Thanks in advance
You should set the height attribute of your textview to wrap_content in your xml
android:layout_height="wrap_content"
android:scrollbars="vertical"
Just make your texview scrollable:
XML Side:
android:scrollbars = "vertical"
Java Side:
Textview.setMovementMethod(new ScrollingMovementMethod());

Android: creating a layout that goes beyond screen width [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to create a layout like the image below. The blue rectangle in the image represents the screen.
Creating a layout with 4 images is easy, the simpelest way is probably with vertical and horizontal LinearLayouts.
But i don't have a clue how i can go beyond the screenwidth for panning reasons
It's probably not the best solution but since you would like to design outside the screen borders one option would be to use a RelativeLayout for instance and then assign negative margins for the left-side pictures.

Adding Top/Bottom border to TextView programmatically [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a TextView and I need to put a black border on the top of it.
The view is created in java, so I can't use the classic XML divider trick.
Many answers here suggest to put a black line as a background. I tried, but I found out that zooming in the view results in the line overflowing its content (in my application the views' textSizes are constantly changed by pinch zooming, so I can't know a definite width in advance.
So, my question is: is there a simple way to add a top border to a TextView which adapts to its size and which can be created from java without using XML?
Try Compound Drawables. They can be set by XML or in Code.
Use nine patch images for the Drawables or even Shape drawables and they should scale ok with the TextView.

How to stretch layout to edges [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
How can I stretch the black to the edges? Id like to do that then put an overflow to make it a bit transparent :)
Change the dimensions in dimens.xml. By default, there is a border of 16dp around everything, so change that to 0dp. If you continue to want a border around the ListView, you can manually add the padding for that specific object by defining it in the XML layout.
Have you tried match_parent? You could also change the margins.

Weight setting performance [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I heard that the Weight setting inside Layout Parameters can dramatically incrase app's performance. So I am going to use it cautiously, or better - completely avoid using it...
What is the best performance way to build Button that fills 2/3 of avalible width and second Button using the rest (1/3 of width)?
and
What is the best performance way to build Button that fills 100dp of avalible width and second Button using the rest?
Yes, I searched it, but didn't find nothing about the performance, really! :)
Thanks in advance!
So I am going to use it cautiously, or better - completely avoid using it...
Get this thought out of your head quickly. layout_weight can be very handy in the right situations. I would definitely not rule out using it completely. As far as cautiously, I'm not sure what your concerns are but if you use it properly then you will be fine.
What is the best performance way to build Button that fills 2/3 of avalible width and second Button using the rest (1/3 of width)?
The main thing to remember when using layout_weight is that your width of child Views should be 0dp with a horizontal LinearLayout and your height 0dp when using a vertical LinearLayout. See below for a short example. Using layout_weight can help keep your layouts looking the same on different screen sizes/resolutions. If you do something like the below code and don't declare a weightSum in your parent LinearLayout then the CPU will calculate it for you. You only need to declare weightSum if you are doing something where you want empty space or maybe other cases but in general it is best to let it be calculated for you.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
...
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<Button
...
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</LinearLayout>
What is the best performance way to build Button that fills 100dp of avalible width and second Button using the rest?
Using a LinearLayout you can set the width of your first Button to 100dp and the width of your second Button to match_parent. This will result in your first Button being drawn first and your second Button will use the available width.
You can and should use layout_weight when it makes your XML easier. It won't be a problem unless you are having very deep, nested layouts (which is not the case when simply aligning two buttons).
If you worry about performance, take a look at the hierarchy viewer every now and then and check if your layout trees are not too large. Click on one of the top right buttons that estimates the measure/layout/draw times, and see if there are any red dots. Those layouts are possibly too slow, and might need to be optimised.
In general; layout_weights are not that bad.
About implementing, use layout weights for the first question, and 100dp & fill_parent width for the second ( inside linear).

Categories

Resources