试图创建一个可滚动的高分列表,如下所示:
foo 1000
bar 876
foobar 500
foobarfoo 1
Run Code Online (Sandbox Code Playgroud)
我目前正在使用GridView.我想将名称列宽设置为屏幕的60%,将得分列宽度设置为40%.可能吗?
目前我正在通过costum适配器尝试.这是它的getview功能:
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv;
if (convertView == null) {
tv = new TextView(context);
tv.setTextSize(25);
tv.setTextColor(Color.WHITE);
if (position % 2 == 0)
{
tv.setLayoutParams(new GridView.LayoutParams((width/10)*6, 50));
}
else
{
tv.setLayoutParams(new GridView.LayoutParams((width/10)*4, 50));
}
}
else {
tv = (TextView) convertView;
}
tv.setText(texts[position]);
return tv;
}
Run Code Online (Sandbox Code Playgroud)
布局由gridview和底部的按钮构建.XML文件是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/top">
<GridView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/grid"
android:numColumns="2"
android:columnWidth="0dp"
> …Run Code Online (Sandbox Code Playgroud) 所以,我遇到了以下"问题",我真的很好奇它背后的原因.
考虑以下:
public class B
{
}
public class A<T>
{
private void AFunc(T t)
{
FuncRequireB((B)t); // Not allowed
FuncRequireB(t as B); // Allowed
}
private void FuncRequireB(B b)
{
}
}
Run Code Online (Sandbox Code Playgroud)
我知道优雅的解决方案是在课堂上将T定义为B,但我想知道为什么在这种情况下"(B)t"和"t as B"不同.我知道"as"是安全的,所以如果无法进行转换,它只能生成null,而另一方面,如果转换不成功,则显式转换会抛出异常,但编译器为什么要关心这个?在这种情况下,我认为他们之间没有区别.
先感谢您!