我现在进入的案例很难解释,因此我将编写一个更简单的版本来解释这个问题.
我有一个Observable.from()发出由文件定义的文件序列ArrayList.所有这些文件都应该上传到服务器.为此我有一个功能,完成工作并返回一个Observable.
Observable<Response> uploadFile(File file);
Run Code Online (Sandbox Code Playgroud)
当我运行这段代码时,它变得疯狂,它会Observable.from()发出所有文件并将它们全部上传到一个文件中,或者至少可以处理它可以处理的最大线程数.
我希望最多同时上传2个文件.是否有任何操作员可以为我处理这个问题?
我尝试了缓冲区,窗口和其他一些,但它们似乎只发出两个项目,而不是经常上传两个并行文件.我还尝试在上传部分设置最大线程池,但这不能用于我的情况.
这个权利应该有一个简单的运算符吗?我错过了什么吗?
multithreading android functional-programming observable rx-java
我正在尝试创建一个按钮,允许我通过服务录制音频,我希望按钮有文本:"Start Recording".在OnClick事件上,我希望按钮文本更改为:"Stop Recording".
我有这个代码在类中工作,但现在它不在服务中工作,但是,因为我希望音频记录作为服务工作,我似乎无法更改按钮的文本.我对编码很新,所以任何帮助都将不胜感激!
我的代码如下:
类:
public class Test extends AppCompatActivity {
public void Record(View view) {
Intent intent = new Intent(this, RecordService.class);
startService(intent);
}
public void Play(View view) {
Intent intent = new Intent(this, RecordService.class);
stopService(intent);
}
}
Run Code Online (Sandbox Code Playgroud)
服务:
import android.app.Service;
import android.content.Intent;
import android.media.MediaRecorder;
import android.os.Environment;
import android.os.IBinder;
import android.widget.Button;
import android.view.View;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class RecordService extends Service {
MediaRecorder mRecorder;
public static String audioFilePath;
public boolean …Run Code Online (Sandbox Code Playgroud) 我想设置layout_weight的TextView与tv_long_text至80%,在以下LinearLayout的垂直方向.
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tv_short_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
tools:text="short text" />
<TextView
android:id="@+id/tv_long_text"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.8"
tools:text="a pretty long text" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
上述方法无法正常工作,因为textview父级的方向是垂直的.
因此,我尝试android:layout_width="match_parent"在xml中设置,然后通过获取测量的宽度在运行时设置宽度,然后将宽度设置为80%但是getMeasuredWidth给出0.
int measuredWidth = longTextView.getMeasuredWidth();
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) longTextView.getLayoutParams();
params.width = (int) (measuredWidth * 0.8);
longTextView.setLayoutParams(params);
Run Code Online (Sandbox Code Playgroud)
我也尝试在运行时设置layout_weight,但它也不起作用,这可能是因为它的父视图是垂直方向的.
longTextView.setLayoutParams(
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT,
0.8f)
);
Run Code Online (Sandbox Code Playgroud)
对我有用的是为长文本视图添加一些额外的视图.但是,为了尝试以百分比设置此视图的宽度,又添加了2个额外视图.有没有其他有效的方法来做到这一点?
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"> …Run Code Online (Sandbox Code Playgroud) 我想构建一个应用程序来播放由我的Raspberry Pi和Gstreamer发送的 AAC 音频流。这是我在 Gstreamer 中设置的管道:
gst-launch-1.0 audiotestsrc ! faac "bitrate=64000" ! "audio/mpeg, mpegversion=4, rate = 44100, channels = 1" ! mux. mpegtsmux name=mux! udpsink host=224.0.0.1 port=8001
Run Code Online (Sandbox Code Playgroud)
它将 AAC LC 中的音频数据编码为 mp4,比特率为 64000,采样率为 44100,在 mpeg ts 容器中为 1 个通道。
我使用以下代码设置了我的解码器:
format.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
format.setInteger(MediaFormat.KEY_SAMPLE_RATE, 44100);
format.setInteger(MediaFormat.KEY_BIT_RATE, 64 * 1024);
format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
format.setInteger(MediaFormat.KEY_IS_ADTS, 1);
byte[] bytes = new byte[]{(byte) 0x11, (byte)0x90};
ByteBuffer bb = ByteBuffer.wrap(bytes);
format.setByteBuffer("csd-0", bb);
Run Code Online (Sandbox Code Playgroud)
我也试过没有MediaFormat.KEY_IS_ADTS线。(同样的错误)
这是我的解码器的样子:
while (!stopTrack) {
multicastSocket.receive(packet);
decoder.start(); …Run Code Online (Sandbox Code Playgroud) CoordinatorLayout增加AppBarLayout和之间的空间RecyclerView.不知道是否它的Toolbar或AppBarLayout.
手机上呈现的布局的屏幕截图:
Studio上的设计渲染并不是这个空间的方式.
对于发生了什么有什么想法?
代码本身.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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:id="@+id/activity_home_framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
>
<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:id="@+id/activity_home_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ActivitySignIn">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:theme="@style/OTGToolbarTheme"
>
<TextView
android:id="@+id/toolbar_title"
style="@style/textTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="You are logged in"
android:textColor="@color/colorAccent"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/activity_home_articlecontainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="0dp"
android:background="@color/colorPrimary"
android:clipToPadding="false"
android:paddingTop="0dp"
app:behavior_overlapTop="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout> …Run Code Online (Sandbox Code Playgroud) android android-design-library android-coordinatorlayout android-appbarlayout
在我的应用程序中,我正在使用RecyclerView.Adapter自定义Holder类。每个项目都由几个TextView和一个ImageView(图标)组成。问题是RecyclerView快速滚动后显示错误的图像。
例:
因此,我的持有人是:
public class CafeHolder extends RecyclerView.ViewHolder implements OnClickListener {
TextView itemName, itemType, itemMarksCount, itemCommentsCount, itemRating;
ImageView imgCafe;
ImageLoader imgLoader;
private Context context;
private int cafeId;
public CafeHolder(View view, Context context){
super(view);
this.context = context;
itemName = (TextView) view.findViewById(R.id.tvCafeName);
imgCafe = (ImageView) view.findViewById(R.id.imgCafe);
itemType = (TextView) view.findViewById(R.id.tvCafeType);
itemMarksCount = (TextView) view.findViewById(R.id.tvMarksCount);
itemCommentsCount = (TextView) view.findViewById(R.id.tvCommentsCount);
itemRating = (TextView) view.findViewById(R.id.tvRatingCount);
imgLoader = new ImageLoader(context);
view.setOnClickListener(this);
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 我试图DialogFragment弹出并显示可滚动TextView图例,但它只是切断了图例的其余部分。我无法滚动浏览它或任何东西。我尝试添加 aScrollView但它没有任何作用。这是我得到的屏幕:
这是我的 XML 布局文件:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:background="#fff">
<TextView
android:id="@+id/layer_legend_title_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="#fff"
android:textColor="#000" />
<ListView
android:id="@+id/layer_legend_symbols_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:background="#fff"
android:textColor="#000" />
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
我运行此命令将内容添加到TextView:
/**
* A dialog that shows the legend of a ArcGISDynamicMapServiceLayer.
*/
public class LegendDialogFragment extends DialogFragment implements View.OnClickListener {
public static final String TAG = LegendDialogFragment.class.getSimpleName();
private LinearLayout mLinearLayout;
private ArcGISDynamicMapServiceLayer …Run Code Online (Sandbox Code Playgroud) android arcgis android-layout android-scrollview android-dialogfragment
在Kotlin中,当kotlinx.android.synthetic用于访问View(例如Button)时,setEnabled()功能丢失了?该isEnabled()功能仍然存在.
我怎么样setEnabled()?
我正在运行Archlinux系统,我的用户帐户已读取Android SDK和Android Studio文件夹的写入权限/opt/.我收到这些错误:
[76583] WARN - dea.updater.SdkComponentSource - 无法加载文件/home/enlighter/.android/repositories.cfg.[77786] WARN - roid.tools.ndk.GradleWorkspace - 项目"MyApplication"的NDK支持被禁用,因为该项目不包含任何有效的本机配置.WARN - dea.updater.SdkComponentSource - 无法加载文件/home/enlighter/.android/repositories.cfg.
当我尝试将Google存储库从当前版本35更新到版本36时,我收到此错误:
WARN - ectedPackagesStep $ CustomLogger - 无法读取或创建安装属性文件.
即使没有下载所需的文件,更新也会失败.我该如何解决?