PercentRelativeLayout在模拟器上可以,在电话上不能 [英] PercentRelativeLayout okay on Emulator, not okay on phone

查看:61
本文介绍了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天全站免登陆