小编shi*_*tya的帖子

ViewPager里面的部分片段在屏幕底部被截断(Android)

我为我的视图定义了一个基本的协调器布局:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabIndicatorColor="@color/white"
            app:tabMode="fixed"/>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

我的视图寻呼机中有多个选项卡.我发布了一个简单的片段:

<ListView
    android:id="@+id/transferList"
    android:layout_width="match_parent"
    android:layout_height="match_parent"></ListView>

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="@dimen/activity_vertical_margin"
    android:layout_marginRight="@dimen/activity_horizontal_margin"
    android:layout_alignParentRight="true"
    android:src="@drawable/ic_add_white" />
Run Code Online (Sandbox Code Playgroud)

会发生什么是FAB离开屏幕.这不是FAB,但其他具有cardviews/listview的片段在屏幕底部被截断.我四处寻找解决方案,并提出了一个hacky解决方案:从工具栏中删除属性app:layout_scrollFlags ="scroll | enterAlways".

我无法理解可能导致这种情况发生的原因,以及如何解决上述问题解决了问题.它是支持库中的一些错误吗?有没有更好的方法来解决这个问题?我遇到的另一个解决方案是从这里开始 - 将FAB按钮直接保持在活动中的Coordinator布局下,并使其仅在您需要的片段中可见.对我来说似乎不是一个好的解决方案.此外,我的片段中的其他观点也被切断了.

android android-layout android-fragments android-support-library material-design

23
推荐指数
2
解决办法
5871
查看次数

通过Http POST请求从Android上传文件和其他数据

这是从Android发布文件的简单方法.

String url = "http://yourserver.com/upload.php";
File file = new File("myfileuri");
try {
    HttpClient httpclient = new DefaultHttpClient();

    HttpPost httppost = new HttpPost(url);

    InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(file), -1);
    reqEntity.setContentType("binary/octet-stream");
    reqEntity.setChunked(true); // Send in multiple parts if needed
    httppost.setEntity(reqEntity);
    HttpResponse response = httpclient.execute(httppost);
    //Do something with response...

} catch (Exception e) {
    e.printStackTrace();
}  
Run Code Online (Sandbox Code Playgroud)

我想要做的是POST在我的请求中添加更多变量.我怎么做?在POST请求中上传纯字符串时,我们使用URLEncodedFormEntity.

httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Run Code Online (Sandbox Code Playgroud)

而在上传文件时,我们使用InputStreamEntity.

另外,我如何专门上传此文件$_FILES['myfilename']

java post android http-post

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