PercentRelativeLayout 在模拟器上可以,在手机上不行 [英] PercentRelativeLayout okay on Emulator, not okay on phone

查看:34
本文介绍了PercentRelativeLayout 在模拟器上可以,在手机上不行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚实现了 PercentRelativeLayout.我已经添加: compile 'com.android.support:percent:24.2.0' 到 gradle 这样 Android Studio 至少可以识别视图.并添加了 Google API.

I've just implemented PercentRelativeLayout. I've added: compile 'com.android.support:percent:24.2.0' to the gradle so Android Studio at least recognizes the view. And added the Google API.

我遇到了渲染问题.在模拟器中,我的显示器工作正常.安装在运行 Android 4ish 的旧手机上,出现 TextViews 但不显示图像视图.

I'm having rendering problems. In the emulator, my display works fine. Installed on an older phone running Android 4ish, TextViews appear but not image views.

在预览渲染中(在设计选项卡中),当我切换到 API 23 而不是 API 24 时会显示 ImageViews.

In the preview render (in design tab) the ImageViews show when I switch to API 23, but not API 24.

我觉得这只是工作.对此有任何已知的修复吗?不幸的是,视图对于缩放我的布局至关重要.

I feel like this was just working. Any known fixes to this? Unfortunately the view is essential to scale my layout.

预览突然再次工作,重新启动了几次android studio.没有改变其他任何东西.

The preview suddenly works again with several restarted of android studio. Didn't change anything else.

布局在预览中一直工作到 API 16,但仍然无法在手机上工作.ImageViews 不显示.

The layout works in preview all the way back to API 16 but still not working on phone. ImageViews don't show up.

XML 下面

<LinearLayout 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:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.y"
tools:showIn="@layout/app_bar_main"
android:background="#FFF"
android:weightSum="1"
android:orientation="vertical">

 <ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView"
    android:scrollIndicators="top">

    <android.support.percent.PercentRelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="This text appears correctly"
            android:textSize="28sp"
            android:id="@+id/textMainTitle"
            android:layout_gravity="center"
            android:layout_alignParentTop="true"
            android:textColor="#ffffff"
            android:singleLine="true"/>

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="As does this text"
            android:id="@+id/textMainSubTitle"
            android:layout_gravity="center_horizontal"
            android:layout_below="@id/textMainTitle"
            />


        <ImageView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/btnIntro"
            android:src="@drawable/button1" //DOES NOT APPEAR IN PHONE
            app:layout_widthPercent="30%"
            app:layout_heightPercent="25%"
            android:layout_below="@id/textMainSubTitle"
            android:layout_marginStart="10dp"
            android:layout_marginLeft="10dp" />

   </android.support.percent.PercentRelativeLayout>

 </ScrollView>


</LinearLayout>

推荐答案

终于想通了.问题实际上出在 XML 中.在这里发布以供参考,希望将来有人会发现它有帮助.

Finally figured this out. Problem was actually in the XML. Posting here for reference in hopes someone will find it helpful in the future.

问题来自于设置 layout_heightPercentlayout_widthPercent.出于某种原因,这不允许显示有问题的视图.我不认为这与缩放纵横比有任何关系,因为按钮也存在问题(无需保持纵横比.)

The problem came from setting layout_heightPercent and layout_widthPercent. For some reason this does not allow the view in question to display. I do not believe it has anything to do with scaling the aspect ratio as the problem exists with buttons as well (with no aspect ratio to maintain.)

但如果您在使用 PercentRelativeLayout 时遇到可见性问题,请参见下文.

But if you're having visibility problems with a PercentRelativeLayout, see below.

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/btnIntro"
        android:src="@drawable/button1" 
        app:layout_widthPercent="30%"       // MUST SET ONE 
        app:layout_heightPercent="25%"      // OR OTHER NOT BOTH
        android:layout_below="@id/textMainSubTitle"
        android:layout_marginStart="10dp"
        android:layout_marginLeft="10dp" />

这篇关于PercentRelativeLayout 在模拟器上可以,在手机上不行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆