Android 从自定义文本视图中删除线性布局
我有一个自定义文本视图,它位于LinearLayout的内部Android 从自定义文本视图中删除线性布局,android,android-layout,android-custom-view,android-xml,Android,Android Layout,Android Custom View,Android Xml,我有一个自定义文本视图,它位于LinearLayout的内部 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:tools=
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<TextView
android:id="@+id/timerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="2"
android:ellipsize="end"
tools:text="Only on 22 of July, 2019"
android:textColor="@color/white" />
</LinearLayout>
显然,线性布局是无用的。但是,如何在不将文本视图数据移动到其他布局中的代码和子级的情况下删除此内容?您可以使用文本视图替换线性布局:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="2"
android:ellipsize="end"
tools:text="Only on 22 of July, 2019"
android:textColor="@color/white"
/>
我在问更多关于课堂的问题。如何在CustomTimerView中为textView充气?我只有一些错误,因为某些原因,文本视图样式不适用是的。怎么可能呢?我只有颜色,我没有mentioned@Strangelove我认为如果你还没有做过,最好再问一个关于风格的问题。
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="2"
android:ellipsize="end"
tools:text="Only on 22 of July, 2019"
android:textColor="@color/white"
/>
class CustomTimerView(context: Context, attributeSet: AttributeSet) : TextView(context, attributeSet) {
init {
TextView.inflate(context, R.layout.custom_timer_layout, null)
}
fun setDates(ob: Promo) {
val startDate = getStartDate(ob)
val endDate = getEndDate(ob)
if (startDate.get(Calendar.MONTH) != endDate.get(Calendar.MONTH)) {
this.text = getInDifferentMonths(context!!, ob)
} else {
if (startDate.get(Calendar.DAY_OF_MONTH) == endDate.get(Calendar.DAY_OF_MONTH)) {
this.text = getOnlyOneDay(context!!, ob)
} else {
this.text = getInOneMonth(context!!, ob)
}
}
}
}