如何只更改 BuiltInView 中的一个 属性?
How to change only one property of a BuiltInView?
我是 Xamarin Android 初学者。在我正在编写的一个应用程序中,我创建了一个带有 RadioGroup 的 Activity,它下面有一个按钮。
一切都很好,直到我的单选按钮包含太多文本以至于单选组 运行 离开了 phone 的屏幕,按钮被隐藏了。
所以,我在互联网上搜索,发现我可以使 RadioGroup 可滚动,方法是将其设为 ListView,并将 ListView 设置在按钮上方。
此外,我发现 Xamarin Android 提供了 BuiltInView SimpleListItemSingleChoice,这是一个作为 ListView 的现成单选组。
所以,我实现了这个,一切都很好,除了 BuiltInView 的每个项目中的文本字段被缩短(即我的单选按钮选项给用户)。
我要申请属性
android:layout_height="wrap_content"
这样单选按钮的长文本标签就不会被缩短。
我的问题是,如何将其应用于 BuiltInView 的每个项目?
我尝试定义自己的自定义视图,但在尝试使其可检查时遇到了 运行 问题,所以我想知道是否有更简单的方法通过使用已经提供的 BuiltInView 来解决问题.
在 MyListAdapter GetView 中,我有
view = (context.LayoutInflater.Inflate(Android.Resource.Layout.SimpleListItemSingleChoice, parent, false));
在我的 Activity 中,我有
myListAdapter = new Adapters.MyListAdapter(this, myStrings, false);
myListView.Adapter = myListAdapter;
由于 BuiltInView 不提供 xml 文件(或者我不知道在 Xamarin 中的何处访问它),我将以下代码添加到自定义适配器的 GetView 方法中:
var textLabel = view.FindViewById<TextView>(Android.Resource.Id.Text1);
//I added these 2 lines to set the WrapContent property on each element of the BuiltInView
AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(AbsListView.LayoutParams.MatchParent,
AbsListView.LayoutParams.WrapContent);
textLabel.LayoutParameters = layoutParams;
我是 Xamarin Android 初学者。在我正在编写的一个应用程序中,我创建了一个带有 RadioGroup 的 Activity,它下面有一个按钮。
一切都很好,直到我的单选按钮包含太多文本以至于单选组 运行 离开了 phone 的屏幕,按钮被隐藏了。
所以,我在互联网上搜索,发现我可以使 RadioGroup 可滚动,方法是将其设为 ListView,并将 ListView 设置在按钮上方。
此外,我发现 Xamarin Android 提供了 BuiltInView SimpleListItemSingleChoice,这是一个作为 ListView 的现成单选组。
所以,我实现了这个,一切都很好,除了 BuiltInView 的每个项目中的文本字段被缩短(即我的单选按钮选项给用户)。
我要申请属性
android:layout_height="wrap_content"
这样单选按钮的长文本标签就不会被缩短。
我的问题是,如何将其应用于 BuiltInView 的每个项目?
我尝试定义自己的自定义视图,但在尝试使其可检查时遇到了 运行 问题,所以我想知道是否有更简单的方法通过使用已经提供的 BuiltInView 来解决问题.
在 MyListAdapter GetView 中,我有
view = (context.LayoutInflater.Inflate(Android.Resource.Layout.SimpleListItemSingleChoice, parent, false));
在我的 Activity 中,我有
myListAdapter = new Adapters.MyListAdapter(this, myStrings, false);
myListView.Adapter = myListAdapter;
由于 BuiltInView 不提供 xml 文件(或者我不知道在 Xamarin 中的何处访问它),我将以下代码添加到自定义适配器的 GetView 方法中:
var textLabel = view.FindViewById<TextView>(Android.Resource.Id.Text1);
//I added these 2 lines to set the WrapContent property on each element of the BuiltInView
AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(AbsListView.LayoutParams.MatchParent,
AbsListView.LayoutParams.WrapContent);
textLabel.LayoutParameters = layoutParams;