相关疑难解决方法(0)

固定宽高比视图

我如何实现固定的宽高比View?我想要一个宽高比为1:1的物品GridView.我认为将孩子分类比把它分类更好GridView

编辑:我认为这需要以编程方式完成,这没问题.另外,我不想限制大小,只限制宽高比.

android view aspect-ratio viewgroup

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

如何在PercentRelativeLayout中使用layout_aspectRatio?

我尝试在视图上实现16:9的宽高比PercentRelativeLayout.

所以我把这行放在build.gradle文件中: compile 'com.android.support:design:23.0.1'

我用这个布局:

<android.support.percent.PercentRelativeLayout
    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="wrap_content">

    <ImageView
        android:layout_width="match_parent"
        app:layout_aspectRatio="178%"
        android:scaleType="centerCrop"/>

</android.support.percent.PercentRelativeLayout>
Run Code Online (Sandbox Code Playgroud)

问题:

  • Android Studio警告我:'layout_height' should be defined为了ImageView.
  • 当我运行我的项目时,我得到了:Error:(15) No resource identifier found for attribute 'layout_aspectRatio'.

那有什么不对?

android android-layout android-constraintlayout android-percentrelativelayout

13
推荐指数
3
解决办法
8653
查看次数