Comments (11)
Hi,
I am sorry, I do not understand what do you mean.
System do support dynamic elements adding.
Can you please show me your code that is not working correctly?
Thanks.
from android-flowlayout.
ViewGroup myViewGroup = (ViewGroup) this.findViewById(R.id.myviewgroup);
LayoutInflater mInflater = LayoutInflater.from(this);
for(int i = 0 ; i<5;i++){
Button button = null;
if(i%2==0){
button = (Button)mInflater.inflate(R.layout.button, myViewGroup, false);
button.setText("偶数"+i);
}else if(i%3==0){
button = (Button)mInflater.inflate(R.layout.button, myViewGroup, false);
button.setText("奇数奇数"+i);
}else{
button = (Button)mInflater.inflate(R.layout.button, myViewGroup, false);
button.setText("超长的超长的超长的"+i);
}
myViewGroup.addView(button);
//................................................................
Some of its properties will not work,for example, margin.
from android-flowlayout.
I have the same issue. When added dynamically, no margins appear. All items are mashed together.
<TextView
android:id="@+id/text_view"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_margin="@dimen/half_margin"
android:padding="@dimen/half_margin"
android:scrollbars="vertical"
android:textColor="@color/primary" />
private void populateTextViews(FlowLayout flowLayout, List<Item> items) {
TextView textView;
try {
for (int i = 0; i < items.size(); i++) {
final Item item = items.get(i);
textView = (TextView) LayoutInflater.from(flowLayout.getContext())
.inflate(R.layout.textview_base, flowLayout, false);
final String text = item.getCategory().getName();
textView.setText(text);
FlowLayout.LayoutParams layoutParams
= new FlowLayout.LayoutParams
(FlowLayout.LayoutParams.WRAP_CONTENT, FlowLayout.LayoutParams.WRAP_CONTENT);
flowLayout.addView(textView, layoutParams);
}
}
catch (Exception e) {
Constants.ignoreError(e);
}
}
from android-flowlayout.
A temporary fix is wrapping the TextView in a FrameLayout. The library respects the FrameLayout for some reason.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/quarter_margin">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:background="@drawable/category_label_light"
android:scrollbars="vertical"
android:textColor="@color/primary" />
</FrameLayout>
from android-flowlayout.
I can confirm this issue, when adding views programmatically to the FlowLayout, margins are not considered. No matter if it is a textview or a FrameLayout.
@tunjid your solution works because you define the padding in the FrameLayout, not the margin, and paddings are respected.
from android-flowlayout.
Confirmed, adding views dynamically causes very broken placement of the children.
from android-flowlayout.
Just add margins dynamically to whatever view you are using in your FlowLayout:
final Button button = new Button(this);
FlowLayout.LayoutParams params= new FlowLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(0, 20, 20, 0); // change this to your liking
button.setLayoutParams(params);
yourFlowLayout.addView(button, 0); // change this to your own FlowLayout
This works for me.
from android-flowlayout.
I'd love to see a fix for this. Temporarily, loolooii's solution works.
from android-flowlayout.
@loolooii Thanks.Your solution works for me。
from android-flowlayout.
TextView view = getLayoutInflater().inflate(R.layout.item_tag_newline, null);
FlowLayout.LayoutParams p = new FlowLayout.LayoutParams(300, 150);
p.newLine = true;
view.setLayoutParams(p);
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:f="http://schemas.android.com/apk/res-auto"
android:id="@+id/tag"
android:layout_width="100dp"
android:layout_height="34dp"
android:layout_gravity="center"
android:layout_margin="5dp"
android:background="@drawable/bg_tag_orange_selector"
android:gravity="center"
android:padding="10dp"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:text="TAT"
android:textColor="@drawable/textcolor_white_selector" />
</FrameLayout>
i write like this, is works.
from android-flowlayout.
Hi, I have created a test for this issue (please check the latest commit).
- I have taken comment from @tunjid and found that in latest version it works fine (and also it took margin correctly).
In your example you are rewriting layout margin that is in you inflating layout by doing this:
FlowLayout.LayoutParams layoutParams
= new FlowLayout.LayoutParams
(FlowLayout.LayoutParams.WRAP_CONTENT, FlowLayout.LayoutParams.WRAP_CONTENT);
flowLayout.addView(textView, layoutParams);
If you remove this layoutParams - it will take correct values from inflated layout.
- wrapping it with one more layout will just hide the problem with overwrited parameters.
- I still can not reproduce issue from @zhumingu as there is no examples of layout itself.
from android-flowlayout.
Related Issues (20)
- HORIZONTAL SCROLL VIEW WITH FLOWLAYOUT HOT 2
- Break before *this* element, only if line breaks at all
- flow layout + RadioGroup HOT 2
- failed to set margins in between two items of flow layout its displaying continuously with no margins , padding ? HOT 4
- Support for TextView and Edit Text HOT 2
- FlowLayoutManager should be constructable using a Context to support setting from XML
- When RecyclerView layout_height set to wrap_content, there will be nothing show on the screen. HOT 3
- Clipped child views on Android 4.1 - 4.3 HOT 1
- Display abnormal when using removeViewAt(int index); HOT 1
- Display Black Background with recyclerview in Samsung Galaxy Star Pro GT-s7262
- [Discussion] Should this library be deprecated in favor of Google's FlexboxLayout? HOT 3
- FlowLayout does not work with enclosing ScrollView HOT 2
- ava.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@70e62c7
- java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@70e62c7 HOT 1
- How to get number of lines
- Gradle 'android-flowlayout-master' project refresh failed with Android Studio 3.0.0
- Get actual height
- Flow Layout doesnot work inside a Recyclerview
- Target API 26 HOT 1
- Check if child on start of line HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-flowlayout.