【发布时间】:2017-05-19 13:47:13
【问题描述】:
我有两个ListViews(leftList,rightList)。我也有一个TextView,我用它作为他们两个中的行视图。
我有一个矩形可绘制形状并将其设置为TextView 的背景。
我想改变这个形状并在左边有圆角。
我尝试了什么:
GradientDrawable gradientDrawable = new GradientDrawable();
// gradientDrawable.setCornerRadius(30);
((GradientDrawable)gradientDrawable.mutate()).setCornerRadius(30);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
viewHolderPattern.digits.setBackground(gradientDrawable);
}
我在 drawable 中创建了一个新布局,设置了右角半径并将其设置为 textView 并使用setBackgroundRescource,但仍然没有工作。
我在两个 listView 中用作项目的 TextView
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/digitsTextView"
android:textSize="15dp"
android:paddingTop="7dp"
android:paddingBottom="8dp"
android:fontFamily="monospace"
android:textColor="@color/selected_items"
android:background="@drawable/digital_text_shape">
</TextView>
形状布局 digital_text_shape.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/orange" />
<solid android:color="@color/orange" />
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="20dp"
android:topRightRadius="0dp"
/>
<padding
android:bottom="0dp"
android:left="20dp"
android:right="0dp"
android:top="0dp" />
</shape>
左列表和右列表
<!-- Left ListView -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:id="@+id/left_listView"
android:divider="@android:color/transparent"
android:dividerHeight="0.1sp"
android:choiceMode="singleChoice"
>
</ListView>
</LinearLayout>
<!-- Right ListView -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ListView
android:id="@+id/right_listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@android:color/transparent"
android:dividerHeight="0.1sp"
android:choiceMode="singleChoice"
>
</ListView>
</LinearLayout>
【问题讨论】:
-
你知道,对于 TextViews 你可以用 /> 来关闭它们。最后不需要第二个标签,除非里面有东西。
-
为什么不让不同的viewholders使用不同的xml?回收者视图.. 使用列表视图来处理像这样的复杂列表似乎需要付出很多努力——回收者的目标是这些丰富、复杂的列表
-
如果创建两个不同的 TextView 背景 xml 文件会怎样。一左一右。然后,如果您在左侧视图中:textView.setBackground(getResources().getDrawable(R.drawable.leftTextViewBackground));,在右侧列表视图中:textView.setBackground(getResources().getDrawable(R.drawable. rightTextViewBackground)); ?
-
@LunarWatcher 你是对的!感谢您提及!
-
@SaikCaskey 我已经有一个viewholder,并且我有我想要修改的textView,我听说过recycler view,我也会尝试,但是现在,我想做这与列表。
标签: android listview textview rounded-corners