- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个应该看起来像这样的屏幕
但是当我按照下面的方式使用 XML 代码创建 View 时
<android.support.constraint.ConstraintLayout 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/fb_constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="me.buddy.buddy.ui.BenefitsActivity$BenefitsFragment">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/fb_animals"
android:src="@drawable/animal_love"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/fb_meal_data"
app:layout_constraintBottom_toTopOf="@id/fb_environment"/>
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/fb_meal_data"
android:src="@drawable/food"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@id/fb_animals"
app:layout_constraintBottom_toTopOf="@id/fb_health"/>
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/fb_environment"
android:src="@drawable/environment"
app:layout_constraintTop_toBottomOf="@id/fb_animals"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/fb_health"
app:layout_constraintBottom_toTopOf="@id/fb_hunger"/>
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/fb_health"
android:src="@drawable/health"
app:layout_constraintTop_toBottomOf="@id/fb_meal_data"
app:layout_constraintBottom_toTopOf="@id/fb_section_label"
app:layout_constraintLeft_toRightOf="@id/fb_environment"
app:layout_constraintRight_toRightOf="parent"/>
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/fb_hunger"
android:src="@drawable/bowl"
app:layout_constraintTop_toBottomOf="@id/fb_environment"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/fb_section_label"/>
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/fb_section_label"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
app:layout_constraintTop_toBottomOf="@id/fb_health"
app:layout_constraintLeft_toRightOf="@id/fb_hunger"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>
我的应用程序中出现如下所示的屏幕
请注意,此布局位于 Activity 的 fragment 内,如 xml 中的工具标记所示。因此,实际布局中会出现额外的 float 操作按钮和后退箭头。
但是我无法理解的是为什么在实际布局中食物碗的图标被推到可见屏幕空间下方。
这个问题有什么解决办法吗?我想尽可能避免使用 Scrollview。
作为引用,父 Activity 的 XML 代码附在下面
<?xml version="1.0" encoding="utf-8"?>
<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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="me.buddy.buddy.ui.BenefitsActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/ab_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/ab_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/app_name">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/ab_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/ab_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_menu_share" />
</android.support.design.widget.CoordinatorLayout>
将 fragment 添加到主要 Activity 的 Java 代码如下:
首先是父类:
setContentView(R.layout.activity_benefits);
Toolbar toolbar = (Toolbar) findViewById(R.id.ab_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.ab_container);
mViewPager.setAdapter(mSectionsPagerAdapter);
然后在 Fragment 类中:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_benefits_dashboard, container, false);
return rootView;}
最佳答案
您尝试解决的问题可以使用 ConstraintLayout
轻松完成 Guideline
您只需定义 2 个水平准则:一个在 33%,另一个在 66%。然后,您所要做的就是根据这些准则来定位您的观点。
这是屏幕的框架实现:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/view1"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#53d94f"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toStartOf="@+id/view2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/view2"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#d9c74f"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/view1"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/view3"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#4f68d9"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toStartOf="@+id/view4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/guideline" />
<View
android:id="@+id/view4"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#d95a4f"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/view3"
app:layout_constraintTop_toTopOf="@id/guideline" />
<View
android:id="@+id/view5"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#4fd4d9"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/view6"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guideline2" />
<View
android:id="@+id/view6"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#c94fd9"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/view5"
app:layout_constraintTop_toBottomOf="@+id/guideline2" />
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.33" />
<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.66" />
</android.support.constraint.ConstraintLayout>
这是输出:
关于android - ConstraintLayout 使单元格项适合屏幕视口(viewport),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47270032/
我想检测鼠标何时离开顶部的视口(viewport)(可以说是向北)。我在网上搜了下How can I detect when the mouse leaves the window? .是一个好的开始
我有一个 HTML 元素,宽 1000 像素,高 850 像素(它实际上是一个 iFrame,在 canvas 标签上包含一个 HTML5 游戏,但我希望这不会有影响)。 我希望元素在平板电脑上呈现,
我正在创建一个 2D 引擎,我想实现对接,所以我需要创建一个视口(viewport)并将屏幕渲染为纹理。 为了渲染视口(viewport),我将帧缓冲区保存到一个 FrameBufferObject
大多数移动页面都提供元视口(viewport)尺寸,例如 出于 iphone 向后兼容的原因,这将在宽度上模拟 320px... 但是当我通过 javascript 检查时 window.screen
我有一个客户提供的宽度为 1440 像素的网站。客户要求我使用以下方法将视口(viewport)设置为 1440 像素对于桌面浏览器,小于 1440 像素的屏幕不显示滚动条。 它确实适用于移动设备、i
我刚刚读了一篇 nice article on viewport这给我留下了几个关于移动设备上的视觉视口(viewport)与布局视口(viewport)的问题。 the width and the
layout viewport和visual viewport的解释可以找到here . 我已阅读 here和 here那个应该使用 如果想针对移动设备优化网页。 我想了解这对横向模式下的 ipho
我想用javascript获取视口(viewport)宽度。但不是常见的虚拟视口(viewport)。我需要逻辑硬件视口(viewport),在我的情况下,它不是设置视口(viewport)元标记的选
我有一个 menu 元素,如果 menu 元素变得在视口(viewport)之外,我想固定到浏览器视口(viewport)的顶部由于滚动。从概念上讲,我的网页看起来类似于下面的示例 HTML,其中菜单
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 4 年前。 Improve this qu
我只包含了“main”的 HTML 代码,因为这是我希望能够通过媒体查询控制的部分。我希望内容只能在小于 480 像素的视口(viewport)上查看,但浏览器似乎隐藏了所有视口(viewport)尺
我不知道如何描述这个,所以最好的办法是链接一个例子:http://www.pascalvangemert.nl/#/profile 无论这个人对侧边栏菜单做了什么都很棒,我很想复制它。我试过检查,但我
我遇到了一页末尾有空白的问题。据我所知,没有元素占据空间。仅当视口(viewport)设置为特定宽度时才会出现该空间。例如,它出现在宽度 940 和 400 左右,但不是 550 或非常宽。 起初我以
iPhone/iPad 等移动设备的视觉视口(viewport)和布局视口(viewport)有什么区别? 网上查了很多资料,还是不清楚。 最佳答案 视觉视口(viewport)是当前显示在屏幕上的页
我正在使用这个元标记来设置移动浏览器上的视口(viewport)大小: 和这个 css 以确保较大的图像不会导致在较小的视口(viewport)上滚动: img { max-width: 95%;
这是针对平板电脑浏览器的,它使用相对于视口(viewport)宽度/高度的尺寸。为简单起见,假设横向。 我在一个全屏容器中有两个 div,就像提供的图像一样。他们有 position:absolute
我在 opengl 中创建了一个迷宫,并且正在尝试创建一个小 map 。为此,我想到在视口(viewport)内创建一个视口(viewport)。我有三种方法,一种用于创建墙壁,另一种用于创建地板,另
所以我有 2 个屏幕:一个级别选择屏幕,使用分辨率为 720 x 405 的 FitViewport,然后是一个游戏屏幕,使用分辨率为 480 x 270 的 FillViewport,按每米像素数
无论视口(viewport)的宽度如何,我都有一个图像幻灯片,我试图将其置于视口(viewport)的中心。如果视口(viewport)比图像宽,使用 margin: auto; 很容易实现,但是,当
我有一个元素,该元素具有从屏幕边缘底部弹出并循环向下弹出(虽然不是完全向下)的动画。下面的代码对此非常有用。但是,有一个问题。当浏览器全屏显示时,百分比占旧视口(viewport)大小而不是新视口(v
我是一名优秀的程序员,十分优秀!