我有卡滚动视图,我试图让我的卡中的内容显示居中。
我试过:
LinearLayout.LayoutParams para=new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT );
para.gravity = Gravity.CENTER;
csvCardsView.setLayoutParams(para);
setContentView(csvCardsView);我还尝试使用布局:
<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>
更新:我无法让滚动视图工作使用上面的布局和创建卡片编程没有给我一个选项来配置文本的卡。
Card optionCard = new Card(this);
optionCard.setText(optionNames.get(currentOptionIndex) + " : "+ option.getDisplayName());
mlcCards.add(optionCard);在mlcCards是ArrayList<Card>的地方,我也尝试在我的ScrollViewAdapter中设置它,但这似乎也不起作用。
@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;
}发布于 2014-03-07 00:20:41
最好是添加全宽、全高(即match_parent)卡,这些卡本身就是内容的中心。
https://stackoverflow.com/questions/22205654
复制相似问题