首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CardScrollView重力

CardScrollView重力
EN

Stack Overflow用户
提问于 2014-03-05 18:05:36
回答 1查看 315关注 0票数 0

我有卡滚动视图,我试图让我的卡中的内容显示居中。

我试过:

代码语言:javascript
复制
LinearLayout.LayoutParams para=new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT );
       para.gravity = Gravity.CENTER;

        csvCardsView.setLayoutParams(para);
        setContentView(csvCardsView);

我还尝试使用布局:

代码语言:javascript
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/options_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

<com.google.android.glass.widget.CardScrollView
        android:id="@+id/options_csv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center">

</com.google.android.glass.widget.CardScrollView>

</LinearLayout>

并将内容设置为此setContentView(R.layout.options_view);

以上内容对文本的放置没有任何影响(总是左上角)。

我的CardScrollView包含一个List<Card>

更新:我无法让滚动视图工作使用上面的布局和创建卡片编程没有给我一个选项来配置文本的卡。

代码语言:javascript
复制
Card optionCard = new Card(this);
        optionCard.setText(optionNames.get(currentOptionIndex) + " : "+ option.getDisplayName());
        mlcCards.add(optionCard);

mlcCardsArrayList<Card>的地方,我也尝试在我的ScrollViewAdapter中设置它,但这似乎也不起作用。

代码语言:javascript
复制
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    LinearLayout.LayoutParams para=new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT );
    para.gravity = Gravity.CENTER;
    View view = mlcCards.get(position).toView();
    view.setLayoutParams(para);
    return view;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-07 00:20:41

最好是添加全宽、全高(即match_parent)卡,这些卡本身就是内容的中心。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22205654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档