One custom layout that can place views horizontally and auto wrap line.
Add the below dependency in your app level build.gradle. Make sure your project level build.gradle includes the jcenter() repository.
compile 'cn.wolfspider:autowraplinelayout:1.0.1'
In your layout file, add the AutoWrapLineLayout.
<cn.wolfspider.autowraplinelayout.AutoWrapLineLayout
android:id="@+id/auto_wrap_line_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
autoWrapLineLayout:verticalGap="1dp"
autoWrapLineLayout:horizontalGap="1dp"
autoWrapLineLayout:fillMode = "0">
/** any view you want to add **/
.......
</cn.wolfspider.autowraplinelayout.AutoWrapLineLayout>
The layout has two style: MODE_FILL_PARENT = 0 and MODE_WRAP_CONTENT = 1. The default value is 0. I gave samlpes in the top to describe the differences of the two modes.
You can set the style in xml or in java. ####xml Set the autoWrapLineLayout:verticalGap, autoWrapLineLayout:horizontalGap and autoWrapLineLayout:fillMode values.
<cn.wolfspider.autowraplinelayout.AutoWrapLineLayout
android:id="@+id/auto_wrap_line_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
autoWrapLineLayout:verticalGap="1dp"
autoWrapLineLayout:horizontalGap="1dp"
autoWrapLineLayout:fillMode = "0">
/** any view you want to add **/
.......
</cn.wolfspider.autowraplinelayout.AutoWrapLineLayout>
mAutoWrapLineLayout.setHorizontalGap(10);
mAutoWrapLineLayout.setVerticalGap(10);
mAutoWrapLineLayout.setFillMode(AutoWrapLineLayout.MODE_FILL_PARENT);
If you have any question or advice, please contact me: [email protected]
Copyright 2016 Hector1990 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.