所以这是我的activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="MainActivity"
>
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/ll_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:fitsSystemWindows="true"
>
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) 所以我希望看到我的布局预览,其中的字段填充了类似默认占位符的字段但是如果我使用绑定,则已经使用了settext属性,并且字段显示为空,因为模型中还没有信息.
<TextView
android:id="@+id/tv_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:gravity="center"
**android:text="@{showBlueportSpotViewModel.name}"**
android:textAllCaps="true"
android:textSize="20sp"
android:textStyle="bold"/>
Run Code Online (Sandbox Code Playgroud)
我试过这个:
android:text="@{showBlueportSpotViewModel.name ?? @string/blueport_placeholder_name}"
Run Code Online (Sandbox Code Playgroud)
但我仍然认为这个视图是空的.
你们有任何解决方法吗?我想一旦找到一个解决方法,它可以用于ImageView和src等示例.
谢谢!
基本上我试图测试,登录不正确后,我在电子邮件字段中显示错误.
该观点是:
<android.support.design.widget.TextInputLayout
android:id="@+id/ti_email"
android:paddingEnd="10dp"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingStart="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/authentication_email_placeholder"
android:inputType="textEmailAddress"
android:maxLines="1"
android:textSize="16sp"
tools:text="@string/placeholder_email"/>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我尝试这样做:
onView(withId(R.id.et_email))
.check(matches(hasErrorText(
ctx.getString(R.string.authentication_error_empty_email))));
Run Code Online (Sandbox Code Playgroud) 我有一个像这样运行的例子:
<Switch
android:id="@+id/sw_state"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:enabled="@{!swAuto.checked}"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="Zustand"
android:textColor="@{swAuto.checked ? @color/outlet_preview_card_text_disabled : @color/outlet_preview_card_text}"
android:textSize="14sp"
tools:textColor="@color/outlet_preview_card_text"/>
Run Code Online (Sandbox Code Playgroud)
但我需要在另一个视图中设置alpha,具体取决于另一个视图的可见性,如:
<LinearLayout
android:id="@+id/ll_global_outlet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/round_background_white"
android:orientation="vertical"
android:alpha="@{ivProgressBar.visibility == View.VISIBLE ? 0.90 : 1}"
android:padding="10dp">
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误:
错误:(45,30)无法解析类型'android.widget.ImageView'上的双向绑定属性'visibility'
知道我做错了什么吗?
这是我应该依赖的观点:
<ImageView
android:id="@+id/iv_progress_bar"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center"
android:visibility="gone"
tools:visibility="visible"
android:background="@drawable/progress_bar_animation"/>
Run Code Online (Sandbox Code Playgroud)