我有一个在活动中膨胀的布局.现在,所有信息都以垂直显示,如下所示. this is how it looks now
但是我想要的是三个textView应该水平放置,然后下三个应该作为下一行,依此类推.我已经发布了它应该看在底部的方式.this is how I want it to look like
这是具有recyclerview的布局
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_my_groups"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
app:reverseLayout="true"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:visibility="gone"
android:onClick="onOutsideClick"
android:orientation="vertical"
app:layoutManager="android.support.v7.widget.StaggeredGridLayoutManager"
app:layout_constraintTop_toBottomOf="@id/rv_selected_groups" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tv_group_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp"
android:background="@drawable/chip_drawable"
android:fontFamily="sans-serif-condensed"
android:gravity="center"
android:textAllCaps="false"
android:textColor="@android:color/black"
android:textSize="14sp" />
还有我夸大版面的Kotlin活动
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GroupsViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.groups_item_row, parent, false)
return GroupsViewHolder(view)
}
如果我的代码不足,对不起.
所需输出
有什么办法可以实现
解决方法:
这是一个完整的例子
第1步:
在build.gradle中添加实现’com.google.android:flexBox:1.1.0′
请注意,从1.1.0版开始,该库应与AndroidX一起使用.如果您使用1.1.0或更高版本,请迁移到AndroidX.
如果您尚未迁移到AndroidX,请使用1.0.0.
步骤2:Activity.xml
<com.google.android.flexBox.FlexBoxLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:flexDirection="row_reverse"
app:justifyContent="center"
app:alignItems="center"
app:flexWrap="wrap">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="@drawable/flexBox_item_background"
android:text="Android"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="@drawable/flexBox_item_background"
android:text="iOS"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="@drawable/flexBox_item_background"
android:text="Windows"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="@drawable/flexBox_item_background"
android:text="Linux"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="@drawable/flexBox_item_background"
android:text="Unix"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="@drawable/flexBox_item_background"
android:text="MaxOS"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="@drawable/flexBox_item_background"
android:text="Java"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="@drawable/flexBox_item_background"
android:text="C++"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="@drawable/flexBox_item_background"
android:text="Python"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="@drawable/flexBox_item_background"
android:text="Kotlin"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="@drawable/flexBox_item_background"
android:text="Hadoop"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="@drawable/flexBox_item_background"
android:text="Solr"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:background="@drawable/flexBox_item_background"
android:text="Lucene"/>
</com.google.android.flexBox.FlexBoxLayout>
步骤3 flexBox_item_background.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/holo_green_light" />
<corners android:radius="5sp"/>
</shape>
输出:
步骤3使用recyclerview的FlexBoxLayout
RecyclerView recyclerView = (RecyclerView)
context.findViewById(R.id.recyclerview);
FlexBoxLayoutManager layoutManager = new FlexBoxLayoutManager(context);
recyclerView.setLayoutManager(layoutManager);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。