gpt4 book ai didi

android - RecyclerView 网格布局管理器 : span count is defaulted to 1

转载 作者:行者123 更新时间:2023-11-29 19:20:21 25 4
gpt4 key购买 nike

尽管我将 gridlayoutmanager 跨度计数定义为 2.. 只有一列是模拟器的结果。我尝试用 XML 更改卡片的宽度,但效果不佳。主要 Activity :

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pb = (ProgressBar) findViewById(R.id.pb1);
pause = (ImageButton) findViewById(R.id.pause);
refresh = (ImageButton) findViewById(R.id.refresh);
sb = (SeekBar) findViewById(R.id.seekBar);
pause.setVisibility(pause.INVISIBLE);
sb.setVisibility(sb.INVISIBLE);
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
lmanager = new LinearLayoutManager(this);
gmanager = new GridLayoutManager(this,2);

rv = (RecyclerView) findViewById(R.id.rv1);
//initializeRecyclerView();
rv.setLayoutManager(lmanager);
pb.setVisibility(pb.VISIBLE);
if(isconnected()) {
new Podcast_async(this).execute("https://www.npr.org/rss/podcast.php?id=510298");
}
}

网格布局 XML:

<android.support.v7.widget.CardView
android:layout_below="@+id/tool_bar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_height="150dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:layout_width="150dp">

<ImageView
android:layout_width="match_parent"
android:layout_height="115dp"

android:id="@+id/imageView4" />

<ImageButton
android:layout_width="match_parent"
android:layout_height="118dp"

android:background="@null"
app:srcCompat="@drawable/playcircle"
android:id="@+id/imageButton2" />

<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_marginTop="120dp"

android:id="@+id/textView4"
android:layout_height="30dp"
android:gravity="center_horizontal" />
</android.support.v7.widget.CardView>

Emulator

最佳答案

使用代码并为 recyclerview 设置 Adapter,然后在 Adapter 中扩充 gridlayout.xml。

RecyclerView.LayoutManager layoutmanager = new GridLayoutManager(this, 2);
recyclerview.setLayoutManager(layoutmanager);

对于适配器使用你的布局

    @Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.GridLayout.xml, parent, false);
return new Adapter.ViewHolder(view);
}

关于android - RecyclerView 网格布局管理器 : span count is defaulted to 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42663952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com