我的应用程序中有一个底页,我想在其中使用折叠工具栏布局.但当我打开底部页面时,折叠工具栏布局将消失,我必须向下滚动才能看到它.
另一个问题是针对我想要成为滚动模式引脚的线性布局不起作用的引脚模式.
当我添加折叠工具栏布局时,我的底部工作表也不会打开全屏.
这是我的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"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="360dp"
android:background="#ffffff"
app:elevation="5dp"
app:expanded="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expanded="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="252dp"
app:layout_constraintBottom_toTopOf="@+id/indicator"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<me.relex.circleindicator.CircleIndicator
android:id="@+id/indicator"
android:layout_width="match_parent"
app:ci_drawable="@drawable/circleindicator_round"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:gravity="bottom"
android:visibility="visible"/>
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
android:layout_gravity="bottom"
android:visibility="visible"
app:titleTextColor="@color/black">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e9e7e7"
android:fillViewport="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
谢谢您的回答.
我在我的应用程序中使用LiveData,DataBinding和Kotlin.
我为RecyclerView定义了一个绑定适配器,如下所示:
class MainListBindings {
private val TAG = "TasksListBindings"
companion object {
@JvmStatic
@SuppressWarnings("unchecked")
@BindingAdapter("main_items")
fun setItems(recyclerView: RecyclerView, items: MutableLiveData<List<Homeitem>>? = null) {
val adapter: RecyclerMainAdapter = recyclerView.adapter as RecyclerMainAdapter
//prevent use of null list
items?.let {
adapter.swapData(items)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
和我的reyclerView in XML分配给这个bindingAdapter,如下所示:
<android.support.v7.widget.RecyclerView
android:id="@+id/main_recycler"
app:main_items="@{viewmodel.items}"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)
在我的ViewModel中,我使用过
val items = MutableLiveData<List<Homeitem>>()
Run Code Online (Sandbox Code Playgroud)
创建列表.
但我在构建应用程序时遇到此错误:
Found data binding errors.
****/ data binding error ****msg:Cannot find the setter for attribute 'app:main_items' with parameter type android.arch.lifecycle.MutableLiveData<java.util.List<project.data.pojo.Homeitem>> on android.support.v7.widget.RecyclerView. file:/home/user/Yara/bazinama_mag/bazinama/app/src/main/res/layout/fragment_main.xml …Run Code Online (Sandbox Code Playgroud) 我有一个数据类,我Entity从它为我的数据库创建了一个。
这是我的数据类:
@Entity
@Parcelize
data class Tapligh(
@PrimaryKey(autoGenerate = true)
var id: Long,
@SerializedName("title") var title: String?,
@SerializedName("type") var type: Int?,
@SerializedName("os") var os: Int?,
@SerializedName("logo") var logo: String?,
@SerializedName("template") var template: String?,
@SerializedName("action") var action: String?,
@SerializedName("date") var date: String?,
@Embedded
@SerializedName("videos") var videos: Videos?,
) : Parcelable {
fun getTaplighType(): Int {
return when (this.type) {
0 -> TaplighType.IMAGE.type
1 -> TaplighType.VIDEO.type
else -> TaplighType.NATIVE.type
}
}
}
@Parcelize
data class Videos(
@SerializedName("land") var land: String?, …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用了 RecyclerView,但是当我滚动我的 RecyclerView 时,我的项目将消失!我在很多 RecyclerView 中使用了这段代码,但这次我不知道发生了什么。有我的活动代码:
public class ActivityStartup extends AppCompatActivity {
Toolbar toolbar;
DrawerLayout drawerLayout;
NavigationView navigationView;
RecyclerView menuListRecycler;
RecyclerView schedualRecycler;
private List<ReminderModel> tempSchedualArray = new ArrayList<>();
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
LinearLayoutManager mSchedualLayoutManager = new LinearLayoutManager(ActivityStartup.this);
private FloatingActionButton mAddReminderButton;
RecyclerView.Adapter mSchedualAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
toolbar = (Toolbar) findViewById(R.id.toolBar);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationView = (NavigationView) findViewById(R.id.navigationView); …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用实时数据,并且我有一个从ViewModel.
在我的视图模型中,我有一个列表:
var songs: MutableLiveData<List<Song>> = MutableLiveData<List<Song>>()
Run Code Online (Sandbox Code Playgroud)
在我的视图模型中的一个函数中,我这样做:
songs.value?.find { it.id == song.id }.also {
when (song.isFavorite) {
true -> song.isFavorite = false
false -> song.isFavorite = true
}
}
Run Code Online (Sandbox Code Playgroud)
我将songs在 m 片段中的一个项目中更改一个布尔值,我观察这个列表,如下所示:
viewModel.songs.observe(this , Observer {
Log.d(TAG , "songs changed")
})
Run Code Online (Sandbox Code Playgroud)
但歌曲不会在此更改后通知。
为什么会发生这种情况?
谢谢您的回答。
我正在使用改造来下载一些媒体文件,如视频,mp3,jpg,pdf,...在我的应用程序中.当我想下载一个55MB格式为mp4的大文件时,这是一个问题.当我想下载此文件时,我收到如下错误:
OutOfMemoryError threw while trying to throw OutOfMemoryError; no stack trace available
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
private void downloadFile() {
ArrayList<FileModel> filesInDB = G.bootFileFromFileDB();
for (final FileModel fm : filesInDB) {
APIService downloadService = ServiceGenerator.createServiceFile(APIService.class, "username", "password");
//Id of apk file that you want to download
Call<ResponseBody> call = downloadService.downloadFileWithDynamicUrlSync("file/download/" + String.valueOf(fm.getFileId()));
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccess()) {
Log.d("LOGOO", "server contacted and has file");
boolean writtenToDisk = writeResponseBodyToDisk(response.body(), fm.getFileName(), fm.getFileExtension());
response = null;
Log.d("LOGOO", "file …Run Code Online (Sandbox Code Playgroud) 我正在使用Retrofit向我的服务器发送和接收请求.
我有一个类似下面的模型,我必须将它发送到我的服务器,但这个模型中的一些变量不能发送到服务器.
public class SelectedListModel implements Serializable {
@SerializedName("p_id")
@Expose
private Long pId;
@SerializedName("p_qty")
@Expose
private Double pQty;
@Expose(serialize = false , deserialize = false)
private String pName; //Have not to send to server
@Expose(serialize = false , deserialize = false)
private String pPrice; //Have not to send to server
@Expose(serialize = false , deserialize = false)
private String pImageUrl; //Have not to send to server
}
Run Code Online (Sandbox Code Playgroud)
因此,我从服务器得到的回复是400.我用它@Expose(serialize = false, deserialize = false)来忽略那些没有发送到服务器的变量.但它不起作用.有没有办法做到这一点,或者我必须为我的服务器创建另一个模型?
我有两个应用程序(A,B),我想将它们链接在一起。当用户使用应用程序A时,通过单击按钮,我想打开应用程序B并向其中发送一些数据。
我在应用程序A中使用此方法去了应用程序B并将一些数据发送到应用程序B:
public static boolean openApp(Context mContext, String packageName) {
PackageManager manager = context.getPackageManager();
Intent goToEncyclopedia = manager.getLaunchIntentForPackage(packageName);
if (goToEncyclopedia == null) {
return false;
}
goToEncyclopedia.addCategory(Intent.CATEGORY_LAUNCHER);
goToEncyclopedia.putExtra("NAME" , "Ehsan");
context.startActivity(goToEncyclopedia);
return true;
}
Run Code Online (Sandbox Code Playgroud)
我在应用A中这样称呼它:
openApp(mContext, "encyclopedia.rasad.app.codenevisha.com.encyclopedia");
Run Code Online (Sandbox Code Playgroud)
当我调用此方法时,它将打开应用程序B,但我要通过putExtra发送的数据不会发送。
这是我在App B中的代码,用于从Intent接收数据:
Bundle bundle = getIntent().getExtras();
if (bundle != null){
String name = bundle.getString("NAME");
Log.i("EXTRAS", name);
}
Run Code Online (Sandbox Code Playgroud) 我正在使用ConstraintLayout以编程方式创建一个视图,我想设置我的按钮视图topTotop的parent和leftToleft的parent.how我可以这样做吗?
非常感谢你.
我的代码如下:
Button button = new Button(MainActivity.this);
ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(widthInt, heightInt);
params.topToTop = // I want to set it parent
params.leftToLeft = // I want to set it parent
params.setMargins(marginStartint , marginTopInt , 0 , 0);
button.setLayoutParams(params);
Run Code Online (Sandbox Code Playgroud) 我正在ConstraintLayout在我的应用程序中创建下面的xml。如您所见,我的第一个项目很好,但是在第二个项目中,我的某些部分textView不在屏幕上!
这是我的XML代码:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ly_user"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
app:layout_constraintRight_toRightOf="parent"
android:id="@+id/im_user_icon"
android:layout_width="@dimen/default_message_icon_size"
android:layout_height="@dimen/default_message_icon_size"
android:src="@drawable/user_pacific"/>
<ImageView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/im_user_icon"
android:id="@+id/im_user_arrow"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/arrow_bg1"/>
<View
android:id="@+id/view_user_guidLine"
android:layout_width="1dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="@id/im_user_arrow"
app:layout_constraintRight_toRightOf="@id/im_user_arrow"/>
<TextView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/view_user_guidLine"
android:id="@+id/tv_user_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="8dp"
android:minWidth="@dimen/default_message_textarea_width"
android:minHeight="@dimen/default_message_textarea_height"
android:background="@drawable/bg_right_text"
android:textColor="@android:color/white"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我知道我可以解决此问题,将以下行添加到textView,但我需要textView做到这一点wrapContent。
app:layout_constraintLeft_toLeftOf="parent"
Run Code Online (Sandbox Code Playgroud)
android ×10
kotlin ×3
android-collapsingtoolbarlayout ×1
android-room ×1
bottom-sheet ×1
data-binding ×1
data-class ×1
deep-linking ×1
gson ×1
java ×1
retrofit ×1
retrofit2 ×1