I have a simple problem but could not solve it with clean solution .
Suppose there are two textviews horizontally next to each other. I want to make them such that
second textview come just right to first and first should grow as much as it can without putting second textview out of screen (means second textview should always be visible).
Hint:you could always use Relative layout and try scaling them in the Graphical layout.
One solution would be, putting the two textViews in a LinearLayout and assign each textView a weight attribute. The LinearLayout divides the space between those views accordingly to the weight. For example if the first textview has weight 3 and the second has weight 2, the width for the first textview would be 3/5 superviews width and the second would be 2/5.
Another solution would be to put the second textView with a fixed width aligned right to the parent RelativeLayout, and the first view to be leftof the second view with the width 'match_parent'
Related
I'm inflating views inside a linearlayout dynamically, however once the linear layout reaches the end of the first row, it cuts off the rest and doesn't start on the second row.
for(int a = 0; a < mSkills.get(i).size(); a++){
View singleSkill = LayoutInflater.from(mContext)
.inflate(R.layout.singleskill, holder.mSkillLayout, false);
TextView skillText = singleSkill.findViewById(R.id.singleskilltext);
skillText.setText(mSkills.get(i).get(a));
holder.mSkillLayout.addView(skillText);
}
For the linear layout I have it set to wrap_content for the height:
<LinearLayout
android:id="#+id/ll_skills"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/tv_description"
android:layout_margin="16dp"/>
I've tried setting it to a defined height e.g 300dp however that doesn't work either.
How can I make the layout start on the second row, once the first is full?
Linear Layout can either fill views horizontally or vertically so the 2nd row you are expecting cant to be done with linear layout only. you can try a horizontal scroll view for that to scroll horizontally. For the exact view-like flow that you described, you can use this 3rd party https://github.com/nex3z/FlowLayout
It can manage the flow of your dynamically inflated view such as if there is no space in the first line then it will put the next view in the second line.
also, you can use material design library chips https://material.io/components/chips/#usage
LinearLayout works exactly how it has to be because you specify it as horizontal. For such behavior, you need RecyclerView With GridLayoutManager or create your own layout;).
Actually it's doing exactly as it should be, LinearLayout is Linear!, and place its subviews in a single horizontal or vertical row.
My advice to you is that create dynamic horizontal LinearLayout as you already doing with TextViews. and put every 3 or 4 textviews (depending on screen size) inside it.
and put all LinearLayouts inside one vertical LinearLayout...
Of course in your case, it's not a good idea, the best thing you can do is to use recycler view. but I consider you have problem with that.
how can i mange Textview in layout.? please help me..
how can i set textview and border then again textview.
Just create a horizontal LinearLayout, and add an ImageView, a TextView, a View with width 2dp and height match_parent, and a TextView as children.
Either repeat that for every row, or use the recommended approach of using a ListView with the above mentioned layout as rows.
I'd use two compound TextViews: Just create a horizontal LinearLayout, and add a TextView with drawableLeft="#drawable/icon_location" and another one with drawableLeft="#drawable/line_vertical" as children.
For both, a drawablePadding="8dp" or whatever you like best
I use a relative layout. I was wondering, if I want to place a text field to the right "of the middle" of another view (say imageview). How can I do it? I always know how to place it to the right, but it seems that the middles of both views are not aligned
Thanks
Put them both in a relative layout, and set the gravity for the relative layout to center.
I've got next problem.
There is ImageView and button panel below it. I want ImageView to be as large as it needs, but if there is no enough space button panel should be present on screen and Imageview should be shrinked. What is the best solution for that?
Have a look to the android:layout_weight attribute.
What does android:layout_weight mean?
In case there is only 2 views in one layout (ie. Imageview and button) you can put both view in linearlayout and give value 1 for imageview weight layout (and doesn't give any value for the button)
I'm adding a TextView to a parent LinearLayout RelativeLayout programmtically. There is enough space for the text to be displayed horizontally but for some reason the text is displayed vertically. Does anyone know what's going on here?
It's really hard to say what is the problem without looking at your XML and layout code. In my experience, sometimes it happens when the parent layout has height set as WRAP_CONTENT and the views inside it have wrong weight config, for example one has weight but WRAP_CONTENT and the other MATCH_PARENT (Sorry, I don't remember the case exactly). I suggest you check your LayoutParams carefully or set a fixed width and height for the TextView to see what is the problem.
You can also post your code here so we can have a look at it