我使用DataBinding
Api来设置android布局中的视图.这是我的布局.
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="user" type="testing.sampleapp.com.sampleapp.User"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{ "Hello " + user.firstName}"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我希望TextView显示Hello UserName.如何使用数据绑定api实现此目的.
我正在使用Android数据绑定库.我要求如果绑定数小于10,我需要显示一个零附加(如01
,05
),否则显示正常数字.
这是我布局的相关部分:
<TextView
android:id="@+id/tlm_no"
style="@style/BlackSmallTextStyle"
android:layout_width="@dimen/study_plan_icon_width"
android:layout_height="wrap_content"
android:layout_below="@id/tlm_image"
android:gravity="center"
android:fontFamily="sans-serif-light"
android:text="@{studyPlanDetailVM.studyPlanDetail.learningPlanResource[0] < 10 ? `0` + studyPlanDetailVM.studyPlanDetail.learningPlanResource[0] : studyPlanDetailVM.studyPlanDetail.learningPlanResource[0]}" />
Run Code Online (Sandbox Code Playgroud)
但是当我构建项目时,它会抛出以下错误:
The value of attribute “android:text” associated with an element type “TextView” must not contain the '<' character
我该如何解决这个问题?
我正在使用 SingleChildScrollView。它的scrollDirection设置为Horizontal,并且>20个子widgets放置在Row Widget内。我想以编程方式滚动到行中的位置小部件(即第 5 个或第 6 个位置)。有什么方法可以以编程方式做到这一点吗?
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: buttons,
),
)
Run Code Online (Sandbox Code Playgroud) 我有一个ShapeDrawable。我想以编程方式设置CornerRadius(TopLeftRadius和BottomLeftRadius)。
下面是我的xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="5dp"
android:bottom="5dp">
<shape android:shape="rectangle">
<corners android:topLeftRadius="20dp"
android:bottomLeftRadius="20dp"/>
<solid android:color="#A2D368"/>
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud) 我在Android中读过ConstraintLayout,现在我有不同大小的TextView,但我想使用BaseLine Constraint Handle水平对齐两个textviews的内容.如何在xml布局中实现这一点?
这是我的layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"/>
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
app:layout_constraintLeft_toRightOf="@+id/image"
app:layout_constraintTop_toBottomOf="@+id/image"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="100dp"
app:layout_constraintLeft_toRightOf="@+id/text1"
android:textSize="50sp"
android:text="Big Text"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud) 我正在做一个 Flutter 项目。在 pubspec.yaml 文件中声明了一些依赖项。项目在 Android 上构建良好,但是当我尝试在 iOS 上运行时。我收到以下错误。搜索了多个问题,无法弄清楚确切的问题。
.../Flutter/Debug.xcconfig: unable to open file (in target "Runner" in project "Runner") (in target 'Runner' from project 'Runner')
Run Code Online (Sandbox Code Playgroud)
pubspec.yaml 依赖项
flutter_svg: ^0.19.1
flutter:
sdk: flutter
flutter_dash: ^0.0.1
readmore: ^1.0.1
cupertino_icons: ^0.1.3
chopper: ^3.0.6
logging: ^0.11.4
package_info: '>=0.4.3+2 <2.0.0'
provider: ^4.3.2+3
sprintf: ^5.0.0
Run Code Online (Sandbox Code Playgroud) 我使用 Exoplayer 在我的 Android 应用程序中播放视频。我想将播放/暂停按钮放在视频播放器视图的中间(如下图所示)。如何实现这一目标
我只是用一个新的布局来代替 Android 默认的 mediaController。我想知道这是获得以下图像布局的正确方法
媒体控制器.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#CC000000"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dip"
android:orientation="horizontal">
<ImageButton android:id="@+id/pause"
style="@android:style/MediaButton.Play"
android:layout_gravity="center_horizontal"
android:contentDescription="play/pause" />
<TextView android:id="@+id/time_current"
android:textSize="14sp"
android:textStyle="bold"
android:paddingTop="4dip"
android:paddingLeft="4dip"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="4dip" />
<SeekBar
android:id="@+id/mediacontroller_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="32dip" />
<TextView android:id="@+id/time"
android:textSize="14sp"
android:textStyle="bold"
android:paddingTop="4dip"
android:paddingRight="4dip"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dip" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我以前有一个这样的架构
var schema = mongoose.Schema({
type: String,
name: String,
});
Run Code Online (Sandbox Code Playgroud)
现在我的架构发生了变化
var schema = mongoose.Schema({
type: String,
name: String,
content: {
title: {type: String, default: 'Some Title'},
description: {type: String, default: 'Some Description'}
}
});
Run Code Online (Sandbox Code Playgroud)
现在 Schema 已更改,我想使用 dafault 值更新集合中以前的文档,该怎么做?
我使用CoordinatorLayout作为我在activity.xml中的根视图.在那个xml中,我使用NestedScrollView并启用了appbar_scrolling_view_behavior.但是NestedScrollView中的内容包装高度而不是匹配父级.
这是我的布局xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways|snap">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/content"
android:padding="20dp"
android:visibility="gone"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
android ×6
flutter ×2
data-binding ×1
exoplayer ×1
flutter-ios ×1
javascript ×1
layoutparams ×1
mongodb ×1
mongoose ×1
row ×1
scrollview ×1
xml ×1