小编Yur*_*kiy的帖子

通过Retrofit 2上传图片时是否可以显示进度条?

Retrofit 2我目前正在使用,我想在我的服务器上传一些照片.我知道,旧版本使用TypedFile类进行上传.如果我们想要使用进度条,我们应该writeToTypedFile类中重写方法.

使用retrofit 2库时是否可以显示进度?

android retrofit2

69
推荐指数
5
解决办法
5万
查看次数

Android水平滚动图片库

我想用水平图库创建应用程序(有一行和多列).首先我尝试使用gridview,但它只能用作垂直滚动.我可以使用ListViewGridView用于此目的吗?

图像库与水平滚动

android listview gridview

19
推荐指数
2
解决办法
5万
查看次数

如何使用改造从所有响应中获取标头

我将Retrofit库版本 2 与OkHttpClient.

我想从所有响应中获取一些标题。

我找到了一种解决方案OkClient

    public class InterceptingOkClient extends OkClient{
    public InterceptingOkClient()
    {
    }

    public InterceptingOkClient(OkHttpClient client)
    {
        super(client);
    }

    @Override
    public Response execute(Request request) throws IOException
    {
        Response response = super.execute(request);

        for (Header header : response.getHeaders())
        {
            // do something with header
        }

        return response;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我正在使用,我该怎么做OkHttpClient

android retrofit okhttp retrofit2

4
推荐指数
2
解决办法
6320
查看次数

如何在片段交易中添加标签?

FragmentActivity像这样向我添加一个:

getSupportFragmentManager()
            .beginTransaction()              
            .add(R.id.frame_container, fragment)
            .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
            .addToBackStack(fragment.getClass().getName())
            .commit();
Run Code Online (Sandbox Code Playgroud)

但是当我想找到Fragment使用时,FragmentManager它返回null:

 Fragment oldFragment = (Fragment) getSupportFragmentManager().findFragmentByTag(fragment.getClass().getName());
Run Code Online (Sandbox Code Playgroud)

android android-fragments fragment-backstack

1
推荐指数
1
解决办法
2784
查看次数

我怎么知道从服务中可见片段

我正在使用GCM Cloud Listener Service从我的服务器捕获一些通知并通过状态栏显示它 NotificationCompat

出于某种原因,如果我的片段(包含一些可更新项目的列表)现在显示,我不会显示我的通知.

检查的最佳方法是从现在可见的片段CloudListenerService

我想我可以Application用于存储片段的当前状态:

在应用程序类中:

 public class ClientApplication extends Application {    
        public static WeakReference<Fragment> currentFragment;
Run Code Online (Sandbox Code Playgroud)

在我的Fragment:

@Override
public void onResume() {
    ClientApplication.fragment = new WeakReference<>(this);

    super.onResume();
}

@Override
public void onPause() {
    ClientApplication.fragment = null;
    super.onPause();
}
Run Code Online (Sandbox Code Playgroud)

在我的Cloud listener service:

if(ClientApplication.fragment.get() != null && ClientApplication.fragment.get().isVisible()) {
    dosth();
Run Code Online (Sandbox Code Playgroud)

android android-service android-fragments google-cloud-messaging

1
推荐指数
1
解决办法
735
查看次数

如何以编程方式创建两个等宽的 LinearLayout?

我正在尝试以LinearLayout编程方式创建两个等宽: 在此处输入图片说明

mGroupLayout.setOrientation(HORIZONTAL);
mGroupLayout.setWeightSum(2f);

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
        0,
        LinearLayout.LayoutParams.WRAP_CONTENT
        );
params.weight = 1.0f;


leftLayout = new LinearLayout(getContext());
leftLayout.setOrientation(VERTICAL);
leftLayout.setLayoutParams(params);


mGroupLayout.addView(
        leftLayout,
        params
        );

rightLayout = new LinearLayout(getContext());
rightLayout.setOrientation(VERTICAL);
rightLayout.setLayoutParams(params);

mGroupLayout.addView(
        rightLayout,
        params
        );
Run Code Online (Sandbox Code Playgroud)

但是我所有的线性布局都不可见(它们的宽度为 0)。我怎么能这样做?

android android-linearlayout android-layoutparams

0
推荐指数
1
解决办法
649
查看次数