在我的应用程序中,我有这样的activity_main.xml: -
<Coordinator Layout>
<AppBarLayout>
<CollapsingToolbarLayout>
<ImageView/>
<Toolbar/>
</CollapsingToolbarLayout>
</AppBarLayout>
<RecyclerView/>
</Coordinating Layout>
Run Code Online (Sandbox Code Playgroud)
Layout.xml ----- >>>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/theme_background"
android:id="@+id/drawerlayout"
>
<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:fitsSystemWindows="true"
android:id="@+id/activity_main_id"
tools:context="objectdistance.ajai.ram.sita.gallery.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/imagetoolbar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
android:foreground="@drawable/image_header_foreground"
app:layout_scrollFlags="scroll"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="@drawable/theme_background"
app:layout_collapseMode="pin" >
<Spinner
android:id="@+id/spinner_nav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dropDownVerticalOffset="?attr/actionBarSize" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/list" …Run Code Online (Sandbox Code Playgroud) android fastscroll material-design android-recyclerview android-coordinatorlayout
关于如何在SD卡(android 5及以上版本)中编写(和重命名)文件的大量调查结果后,我认为android提供的新SAF需要获得用户写入SD卡文件的许可.
我在这个文件管理器应用程序ES文件资源管理器中看到,最初它采用以下方式读取和写入权限,如图片所示.
选择SD卡后,授予写入权限.
因此我尝试使用SAF的方式相同,但重命名文件失败了.我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rename = (Button) findViewById(R.id.rename);
startActivityForResult(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE), 42);
}
@Override
public void onActivityResult(int requestCode,int resultCode,Intent resultData) {
if (resultCode != RESULT_OK)
return;
Uri treeUri = resultData.getData();
DocumentFile pickedDir = DocumentFile.fromTreeUri(this, treeUri);
grantUriPermission(getPackageName(), treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getContentResolver().takePersistableUriPermission(treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
}
public void renameclick(View v) {
File ff = new File("/storage/sdcard1/try1.jpg");
try {
ff.createNewFile();
} catch (Exception e) {
Log.d("error", "creating");
e.printStackTrace();
}
} …Run Code Online (Sandbox Code Playgroud) android android-sdcard storage-access-framework android-5.0-lollipop documentfile
我想读取和编辑(写入)mp4元数据.特别是我想在android中读/写Tag元数据,如下图所示.
我在互联网上搜索了这个,发现mp4Parser,但我认为mp4Parser不会写标题关键字.
对于.jpg文件,我们使用代表标题的XPKeyword元数据.同样如何为.mp4文件做同样的事情.
在我的应用程序的主布局中,我有一个搜索任务按钮。现在,当用户单击该按钮时,我想将布局 xml 文件更改为 search_layout.xml。我不想为搜索任务创建一个新活动,并想使用我的 activity_main.java 类进行编码。那么如何从现有的 activity_main.xml 膨胀 search_layout 。
我的activity_main 布局是使用Collapsing 工具栏和Recycler 视图协调布局。
在我的 search_layout.xml 我有一个简单的相对布局。
那么如何处理呢?我搜索了这个,但到处都可以找到如何将视图添加到现有视图中。但就我而言,我想完全改变看法。
谢谢
在我的应用程序中,我正在制作一个浮动类型窗口,该窗口出现在任何应用程序或主屏幕的顶部。就像 Facebook 聊天气泡一样。我用一些用于不同操作的按钮制作了浮动窗口拖动山墙。我在窗口中有一个编辑文本布局。我在关注浮动窗口时遇到一些问题。每个布局都没有焦点,编辑文本也不起作用。
我附上了相同的屏幕截图视频。
我的代码是:-
在服务中 oncreate(){}
mFloatingWidget = LayoutInflater.from(this).inflate(R.layout.layout_floating_widget, null);
int layoutType;
if(Build.VERSION.SDK_INT < 26) {
layoutType = WindowManager.LayoutParams.TYPE_PHONE;
} else {
layoutType = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
}
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
layoutType,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.START;
params.x = 0; // Initial Position of window
params.y = 100; // Initial Position of window
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mFloatingWidget, params);
mFloatingWidget.findViewById(R.id.root_container).setOnTouchListener(new View.OnTouchListener() {
private int initialX;
private int initialY;
private float initialTouchX;
private float initialTouchY; …Run Code Online (Sandbox Code Playgroud) 在我的图库应用程序中,我使用媒体内容提供程序图像来扩充回收器视图。长按图像时,我会为用户提供重命名该图像文件的选项。所以我在回收站视图中为每个图像都有完整的文件路径(例如:- /storage/sdcard1/DCIM/100ANDRO/ak.jpg )。然后我想重命名该文件。
现在的问题是,由于提供的文件路径是外部 SD 卡的路径,对于 Android 5 及更高版本,需要 SAF(存储访问框架)来写入文件。
所以通常我们使用此代码使用 SAF 重命名文件:-
public void onActivityResult(int requestCode, int resultCode, Intent resultData){
if (resultCode == RESULT_OK) {
Uri treeUri = resultData.getData();
getContentResolver().takePersistableUriPermission(treeUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION |
Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
DocumentFile pickedDir = DocumentFile.fromTreeUri(this, treeUri);
DocumentFile newFIle = pickedDir.createFile("text/plain","MyFile")
// or rename as
pickedDir.renameTo("fdtd.jpg");
} else {
Log.d("test","NOt OK RESULT");
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我们知道 TreeUri 时就是这种情况。在我的情况下,我知道文件路径,因此想将其转换为 TreeUri。
我无法将文件写入外部 SD 卡。我收到错误消息 EAcess denied。我在互联网上搜索了很多,发现从 Android 4.4 + android 的存储访问框架 (SAF) 写入文件是必需的。
但我正在使用一些能够在 SD 卡上写入(创建/删除/重命名)文件的 android 应用程序。他们没有使用 SAF。
因此,请帮助我了解如何在不使用 SAF 框架的情况下执行此操作。
谢谢
我在画廊应用程序的布局回收器视图中有.
我想要合并一个夹点触摸事件列表器,以便回收器查看列号.进出的增加或减少.
我在很多图库应用程序中看到过这种类型的界面.
实现这一目标的最佳方法是什么,以便过渡顺利.
小视频链接: - http://sendvid.com/s68fiqpd
我尝试使用下面的代码(由@Yogesh Rathi提供),但结果不是我想要实现的.
import android.content.Context;
import android.graphics.Canvas;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
/**
@author yogesh
* */
public class PinchRecyclerView extends RecyclerView {
private static final int INVALID_POINTER_ID = -1;
private int mActivePointerId = INVALID_POINTER_ID;
private ScaleGestureDetector mScaleDetector;
private float mScaleFactor = 1.f;
private float maxWidth = 0.0f;
private float maxHeight = 0.0f;
private float mLastTouchX;
private float mLastTouchY;
private float mPosX;
private float mPosY;
private float width;
private …Run Code Online (Sandbox Code Playgroud) android ×8
android-file ×1
documentfile ×1
fastscroll ×1
file-io ×1
filewriter ×1
java ×1
layout ×1
metadata ×1
mp4 ×1
pinchzoom ×1
xml ×1