0
我有两个ListViews
(leftList,rightList)。我也有一个TextView
,我用它们作为行视图。 我有一个矩形可绘制的形状,并将其设置为TextView
的背景。android - 如何以编程方式设置圆角半径?
我想改变这种形状,左边有圆角。
我试了一下:
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);
}
我已经创造了一个绘制新的布局设置,并设置与setBackgroundRescource
TextView的,但仍然没有工作右上角半径。
,我在这两个列表视图,为项目使用的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你可以clsoe他们/>。除非里面有东西,否则你不需要第二个标签。 – Zoe
为什么不只是有不同的视图使用不同的XML?而回收者视图......看起来像是使用列表视图来完成像这样的复杂列表的很多努力 - 回收站针对这些丰富,复杂的列表 –
如果您创建两个不同的TextView背景xml文件,该怎么办?一个用于左侧,另一个用于右侧。然后如果你在你的左视图中:textView.setBackground(getResources()。getDrawable(R.drawable.leftTextViewBackground));,并在你的右列表视图:textView.setBackground(getResources()。getDrawable(R.drawable。 rightTextViewBackground)); ? – DadoZolic