相关疑难解决方法(0)

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
查看次数

是否可以在 CoordinatorLayout 内轻松地将视图的内容居中放置在 AppBarLayout 下方?

背景

假设您有一个带有 CoordinatorLayout 和 AppBarLayout 的滚动活动,其中顶部标题可以在底部滚动时折叠(可能有 RecyclerView 或 NestedScrollView)。

像这样的东西:

在此处输入图片说明

现在,在内容出现之前,您需要在底部区域(显示文本的地方)的中心放置一个加载视图(例如,一个 ProgressBar 和一个 LinearLayout 内的 TextView)。

问题

我使用 ViewAnimator 在状态之间切换,但是如果我选择将加载视图居中,它会显示在中心下方,因为底部区域会占用更多实际显示的空间(因为您可以滚动它)。

在此处输入图片说明

我试过的

有 2 个解决方案我进行了很好的工作: 1. 获取加载视图及其父视图的大小,并使用它来计算加载视图的顶部边距 2. 将加载视图的底部填充设置为一半上部区域大小(在本例中为 90dp,是上部区域 180dp 的一半)。这有点容易,但是如果活动中任何内容的 UI 或底部区域的父级发生变化,它将破坏居中的修复。

编码

与 IDE 向导中的几乎相同,但在这里:

滚动活动.java

public class ScrollingActivity extends AppCompatActivity {
    private ViewAnimator mViewAnimator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scrolling);
        setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
        mViewAnimator = findViewById(R.id.viewAnimator);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_scrolling, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id …
Run Code Online (Sandbox Code Playgroud)

android android-collapsingtoolbarlayout android-appbarlayout

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