BottomSheetBehavior已在Android设计支持库23.2中引入,但它不会使屏幕的其余部分变暗,也不会阻止与UI的其余部分的交互.无论如何这可以实现吗?
android android-layout android-fragments android-view bottom-sheet
假设这里已经说过,开发人员有责任保留组件实例以实现自己的范围逻辑(因为范围方法将为给定组件返回相同的实例).
通过活动生命周期保持此组件引用的干净方法是什么?
示例:您正在实施MVP模式,因此您需要在Activity中使用Presenter.此演示者可以执行网络操作来下载项目.当设备旋转时,您的Activity将被销毁并重新创建,但您希望保持网络运行并返回预旋转演示者.
在为Presenter提供自定义PerActivity范围的组件范围是解决方案,因此您必须通过此循环保持Component实例,以便在首次启动Activity时注入相同的Presenter实例.
我们怎么处理这个?我想到了一种组件缓存(如HashMap?),它可以由Application类中的Application Component提供.
我想videoView.isAttachedToWindow()在我的片段中使用调用来验证videoview是否已初始化正常并且可以调用.
但是这个调用需要api级别19(当前min是14).videoView.isAttachedToWindow()API级别14及以上的最佳替代方案是什么?
编辑:我的视频视频播放通过Android盒子的HDMI输入流式传输的视频.在某些具有OS 4.0.4的硬件中,视频有时会出现抖动.
java android android-layout android-view android-windowmanager
我想应用一些风格DatePicker.在平台中,attrs.xml我们可以看到以下属性DatePicker:
<declare-styleable name="DatePicker">
...
<!-- The text color for the selected date header text, ex. "2014" or
"Tue, Mar 18". This should be a color state list where the
activated state will be used when the year picker or day picker is
active.-->
<attr name="headerTextColor" format="color" />
<!-- The background for the selected date header. -->
<attr name="headerBackground" />
...
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)
虽然我可以参考android:headerBackground,但出乎意料的是我无法为android:headerTextColor属性做到这一点.所以遵循以下代码styles.xml:
<style name="MyDatePickerStyle" parent="@android:style/Widget.Material.DatePicker">
<item name="android:headerBackground">@color/red</item> …Run Code Online (Sandbox Code Playgroud) android datepicker android-resources android-styles android-attributes
我试图通过使用对象动画师将视图缩放到布局大小.这是一个观点LinearLayout.视图确实拉伸,但直到两个方向(即X和Y)的屏幕尺寸.
这是代码.
我觉得问题是这个:
计算必须完成多少缩放的公式.
zoomTillX = screen_width/zoomView_width;
zoomTillY = screen_height/zoomView_height;
Run Code Online (Sandbox Code Playgroud)或者使用以错误方式完成的Animation属性代码.
请让我知道如何实现放大.
public class MainActivity extends AppCompatActivity {
TextView tv;
double screen_height;
LinearLayout zoomView;
double screen_width;
double zoomTillX;
double zoomTillY;
double zoomView_width;
double zoomView_height;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tv);
zoomView = (LinearLayout) findViewById(R.id.zoomView);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
screen_height = (double)dm.heightPixels;
screen_width = (double)dm.widthPixels;
zoomView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
zoomView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
zoomView_width = (double)zoomView.getMeasuredWidth();
zoomView_height = (double)zoomView.getMeasuredHeight();
} …Run Code Online (Sandbox Code Playgroud) 请考虑以下代码:
Glide.with(<your_context>)
.load(<remote_file_url, local_file_path>)
.into(<imageview>);
Run Code Online (Sandbox Code Playgroud)
Glide代码上面写了很多文件.我只想在logcat中记录remote_file_url或local_file_path.但我不想更改每个文件中的代码.
Glide是否允许记录?如果它允许,那么我需要一个简单的中央方式来打开滑行记录.
供参考:我想要像Retrofit + okhttp允许的方式.在OkHttp,我只需要在一个位置添加拦截器,它将记录有关每个webservice调用的信息,而无需编写任何其他附加代码.
我希望transition在我的android views视图中有一个是Button其他的EditText,转换必须像这个动画
我试过这种方式
布局xml是
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context="app.itc.org.todo.MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:background="@android:color/white"
android:gravity="center_horizontal|center_vertical">
<TextView
android:id="@+id/title_tv"
android:text="@string/to_do"
android:textSize="22sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"/>
<TextView
android:id="@+id/date_tv"
android:textSize="16sp"
android:textColor="@android:color/darker_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/colorGray"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<TextView
android:text="@string/what_do_you_want_to_do_today"
android:textSize="16sp"
android:textColor="@android:color/darker_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"/>
<TextView
android:text="@string/start_adding_items_to_your_to_do_list"
android:textSize="16sp"
android:textColor="@android:color/darker_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/transitions_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<Button
android:id="@+id/add_btn"
android:layout_width="200dp" …Run Code Online (Sandbox Code Playgroud) java animation android android-animation android-transitions
查看ViewModel文档,它说:
换句话说,这意味着如果ViewModel的所有者因配置更改(例如旋转)而被销毁,则不会销毁它.所有者的新实例将重新连接到现有的ViewModel.
如果引用它的活动被销毁,ViewModel如何不被破坏?一旦我们创建一个新活动,它是如何重新连接的?
java android android-viewmodel android-architecture-components
使用Java我可能想使用switch语句初始化最终变量:
final String finalValue;
switch (condition) {
case 1:
finalValue = "One";
break;
case 2:
finalValue = "Two";
break;
case 3:
finalValue = "Three";
break;
default:
finalValue = "Undefined";
break;
}
Run Code Online (Sandbox Code Playgroud)
在Kotlin,尝试做同样的事情:
val finalValue: String
when (condition) {
1 -> finalValue = "One"
2 -> finalValue = "Two"
3 -> finalValue = "Three"
else -> finalValue = "Undefined"
}
Run Code Online (Sandbox Code Playgroud)
导致编译错误.
解决方案正在使用该by lazy组合,但这会创建一个新Lazy实例.
val finalValue: String by lazy {
when (condition) {
1 -> "One"
2 -> …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Dagger 2 添加到我的项目中。我能够为我的片段注入 ViewModels(AndroidX 架构组件)。
我有一个ViewPager,它有 2 个相同片段的实例(每个选项卡只有很小的更改),并且在每个选项卡中,我观察LiveData到更新数据更改(来自 API)。
问题在于,当 api 响应到来并更新 时LiveData,当前可见片段中的相同数据将发送给所有选项卡中的观察者。(我认为这可能是因为 的范围ViewModel)。
这是我观察数据的方式:
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
activityViewModel.expenseList.observe(this, Observer {
swipeToRefreshLayout.isRefreshing = false
viewAdapter.setData(it)
})
....
}
Run Code Online (Sandbox Code Playgroud)
我正在使用这个类来提供ViewModels:
class ViewModelProviderFactory @Inject constructor(creators: MutableMap<Class<out ViewModel?>?, Provider<ViewModel?>?>?) :
ViewModelProvider.Factory {
private val creators: MutableMap<Class<out ViewModel?>?, Provider<ViewModel?>?>? = creators
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
var creator: Provider<out ViewModel?>? = creators!![modelClass]
if (creator == …Run Code Online (Sandbox Code Playgroud) android ×9
java ×5
android-view ×2
dagger-2 ×2
android-architecture-components ×1
android-mvvm ×1
androidx ×1
animation ×1
bottom-sheet ×1
dagger ×1
datepicker ×1
field ×1
final ×1
kotlin ×1
picasso ×1