我使用以下方法将图像从Android上传到服务器.
public void uploadMultipart() {
//getting name for the image
String name = editText.getText().toString().trim();
//getting the actual path of the image
String path = getPath(filePath);
progress = ProgressDialog.show(this, "Subiendo imagen",
"Por favor, espere...", true);
//Uploading code
try {
String uploadId = UUID.randomUUID().toString();
//Creating a multi part request
new MultipartUploadRequest(this, uploadId, Constants.UPLOAD_URL)
.addFileToUpload(path, "image") //Adding file
.addParameter("name", name) //Adding text parameter to the request
.setNotificationConfig(new UploadNotificationConfig())
.setMaxRetries(2)
.startUpload(); //Starting the upload
} catch (Exception exc) {
Toast.makeText(this, exc.getMessage(), Toast.LENGTH_SHORT).show();
}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用AndroidJunit4测试RecyclerView,这是我的测试代码:
package com.kaushik.myredmart.ui;
// all includes
@RunWith(AndroidJUnit4.class)
public class ProductListActivityTest {
@Rule
public ActivityTestRule<ProductListActivity> rule = new ActivityTestRule<>(ProductListActivity.class);
@Test
public void ensureListViewIsPresent() throws Exception {
ProductListActivity activity = rule.getActivity();
View viewByIdw = activity.findViewById(R.id.productListView);
assertThat(viewByIdw,notNullValue());
assertThat(viewByIdw, instanceOf(RecyclerView.class));
RecyclerView productRecyclerView = (RecyclerView) viewByIdw;
RecyclerView.Adapter adapter = productRecyclerView.getAdapter();
assertThat(adapter, instanceOf(ProductAdapter.class));
}
}
Run Code Online (Sandbox Code Playgroud)
我正面临检查适配器的问题.虽然productRecyclerView传递非null测试和RecyclerView的实例,但它在最后一行中跟随错误:
java.lang.AssertionError:
Expected: an instance of com.kaushik.myredmart.adapter.ProductAdapter
but: null
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
at org.junit.Assert.assertThat(Assert.java:956)
at org.junit.Assert.assertThat(Assert.java:923)
at com.kaushik.myredmart.ui.ProductListActivityTest.ensureListViewIsPresent(ProductListActivityTest.java:45)
Run Code Online (Sandbox Code Playgroud)
代码中有什么问题?
java android recycler-adapter android-recyclerview android-junit
这个问题已在这里提出,但它没有解决方案.
我有一个WebView.我想将最小高度设置为WebViewusing minHeight属性,但它不起作用.相同的属性适用于Button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.anshul.webview.WebActivity">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="400dp"></WebView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:minHeight="150dp"
android:text="This is a Button. It's minHeight is set to 150 dp and it works !!"/>
Run Code Online (Sandbox Code Playgroud)
显然,从下图中,WebView不支持该minHeight属性.有谁知道这个问题的解决方案?
我知道你设置的时候
tools:text="Sample text"
Run Code Online (Sandbox Code Playgroud)
在a中TextView,您将在Android Studio的预览模式下看到示例文本,但不会在实际应用中看到.我想为a中的项目做这个RecyclerView,但我似乎无法做到.这是我到目前为止所做的:
在RecyclerView(名为content_feed)中:
tools:listitem="@layout/cell_feed"
Run Code Online (Sandbox Code Playgroud)
在单元格中(名称为cell_feed):
tools:showIn="@layout/content_feed"
Run Code Online (Sandbox Code Playgroud)

这是xml文件:
cell_feed.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/height_feed_cell"
android:layout_marginLeft="@dimen/margin_feed_cell"
android:layout_marginRight="@dimen/margin_feed_cell"
android:orientation="horizontal"
tools:showIn="@layout/content_feed">
<LinearLayout
android:id="@+id/timeLayouts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="@dimen/alpha_feed_secondary_text"
android:textSize="@dimen/size_feed_secondary_text"
android:id="@+id/startTimeText"
tools:text="8:00 AM"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="@dimen/alpha_feed_secondary_text"
android:textSize="@dimen/size_feed_secondary_text"
android:id="@+id/endTimeText"
tools:text="10:00 AM"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_feed_cell_text"
android:layout_toRightOf="@+id/timeLayouts"
android:layout_centerVertical="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_bottom_feed_cell_title"
android:textSize="@dimen/size_feed_cell_title"
android:textStyle="bold"
android:id="@+id/titleText"
tools:text="Event title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="@dimen/alpha_feed_secondary_text"
android:textSize="@dimen/size_feed_secondary_text"
android:id="@+id/captionText"
tools:text="Event caption"/>
</LinearLayout>
<CheckBox
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) android android-studio android-recyclerview android-tools-namespace android-layout-editor
我有一个Fragment包含RecyclerView。但是,由于其中包含很多元素,因此Fragment我想向上滑动列表以查看并检查其中的所有元素Fragment。
早期,此方法对我有帮助,但现在由于某种原因它不起作用:
Espresso.onView(ViewMatchers.withId(R.id.recyclerView)).perform(ViewActions.swipeUp())
Run Code Online (Sandbox Code Playgroud)
我的项目中有很多RecyclerView相同的id:
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
Run Code Online (Sandbox Code Playgroud)
同样在测试中,我写了这样的东西:
onView(allOf( withId(R.id.recyclerView), isDisplayed()))
onView(withId(R.id.recyclerView)).perform(swipeUp())
Run Code Online (Sandbox Code Playgroud)
但是仅在第二行捕获了错误。
android.support.test.espresso.AmbiguousViewMatcherException:'with id:com.fentury.android:id/recyclerView'匹配层次结构中的多个视图。问题视图在下面标有“ **** MATCHES ****”。
android swipe android-fragments android-espresso android-recyclerview

Google Inbox如何显示小吃栏(覆盖,分层)键盘?这不是默认行为,我已经使用基本协调器布局,键盘打开和快餐栏进行了测试:默认行为是显示键盘后面的零食栏.对于这个问题有很多答案:'如何在键盘上方显示小吃栏',但我还没有找到如何重现谷歌自己的收件箱应用程序的零食栏行为.
你能告诉我如何实现这个目标吗?
android android-layout android-activity snackbar android-snackbar
我有一个动画师infinite_rotation,定义为:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:propertyName="rotation"
android:repeatCount="infinite"
android:valueFrom="0"
android:valueTo="360"
android:duration="2000" />
</set>
Run Code Online (Sandbox Code Playgroud)
当时间(时间不确定)到来时我不再需要这个,我打电话infinite_animator.cancel().然后在其布局容器上播放fade_out动画:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:propertyName="alpha"
android:repeatCount="0"
android:valueTo="0.0"
android:duration="1000" />
</set>
Run Code Online (Sandbox Code Playgroud)
生成的动画是,旋转按预期停止,但在淡出时停顿.我错过了什么?
以下是它的外观:
更新:我在使用Kitkat OS的旧三星Tab 4上测试了上述问题.我刚刚使用Marshmallow OS测试了一款相当新的三星Tab 4.动画效果很好.所以我想更好的问题是如何修复旧设备/操作系统上的草率动画?
这是动画调用:
private void animateRefreshButton() {
ImageView iv_refresh = (ImageView) findViewById(R.id.iv_refresh);
if(infinite_animator == null) {
infinite_animator = AnimatorInflater.loadAnimator(this, R.animator.refresh_rotate);
}
infinite_animator.setTarget(iv_refresh);
infinite_animator.start();
}
Run Code Online (Sandbox Code Playgroud)
hideRefreshButton()应用程序确定刷新完成时启动.这是取消和淡出动画的调用:
private void hideRefreshButton() {
if(infinite_animator != null) {
infinite_animator.cancel();
}
Animator anim = AnimatorInflater.loadAnimator(this, R.animator.refresh_fadeout);
anim.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator …Run Code Online (Sandbox Code Playgroud) 我想创建一个下拉导航.我画了这幅素描:

我已经尝试了一个微调器,但我不想要那个组合框,只有那个列表,按钮点击显示
android android-ui android-listview android-spinner drop-down-menu
谁能解释为什么isAttachedToWindow()是false而不是true?我似乎有附件问题。
据我了解,setContentView(rl)应该将其附加RelativeLayout到窗户上。我缺少什么?
public class TestActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final RelativeLayout rl = new RelativeLayout(this);
setContentView(rl);
boolean isAttached = rl.isAttachedToWindow();
}
}
Run Code Online (Sandbox Code Playgroud) 我需要使用意图过滤器指定我的登录活动:
<activity
android:name=".view.LoginActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="com.example.sdk.LOGIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
我想这样做的原因是我正在开发一个我想在几个项目中使用的 SDK,这是我能弄清楚如何通知 SDK 是登录活动的最好方法,而它是仅在 app 模块中定义。
在我做这样的声明后,我开始像这样的登录活动(在库和应用程序中):
Intent intent = new Intent();
intent.setAction("com.example.sdk.LOGIN");
context.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
有可能在同一设备上同时安装两个或多个依赖于同一个 SDK 的应用程序。如果我理解正确,在这种情况下,在这些应用程序中的每一个中,Activity start 将启动一个随机登录活动(应用程序 A 中的调用可能会启动应用程序 B 的登录)。
也欢迎提出重用登录相关逻辑的替代方法的建议,而不是依赖意图过滤器。
android intentfilter android-intent android-activity android-intent-chooser
android ×10
java ×4
android-ui ×1
android-view ×1
animation ×1
intentfilter ×1
multipart ×1
snackbar ×1
swipe ×1
upload ×1
webview ×1