Questions tagged [android-percentrelativelayout]

Subclass of RelativeLayout that supports percentage based dimensions and margins. You can specify dimension or a margin of child by using attributes with "Percent" suffix. The tag is to be used with the [android] tag.

Subclass of RelativeLayout () that supports percentage based dimensions and margins. You can specify dimension or a margin of child by using attributes with "Percent" suffix.

Usage:

Please, use the tag jointly with tag.

Example:

<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="match_parent"/>
    <ImageView
        app:layout_widthPercent="50%"
        app:layout_heightPercent="50%"
        app:layout_marginTopPercent="25%"
        app:layout_marginLeftPercent="25%"/>
</android.support.percent.PercentFrameLayout/>

It is not necessary to specify layout_width/height if you specify layout_widthPercent. However, if you want the view to be able to take up more space than what percentage value permits, you can add layout_width/height="wrap_content". In that case, if the percentage size is too small for the View's content, it will be resized using wrap_content rule.

From PercentRelativeLayout:

This class was deprecated in API level 26.1.0.
consider using ConstraintLayout and associated layouts instead.

49 questions
19
votes
3 answers

PercentRelativeLayout is more Performant?

I always use LinearLayout and RelativeLayouts, and i was reading about the "new" PercentRelativeLayout. I have a few questions: Should i always start using this one or only in cases of nested weights with linearlayout? Is this more performant than…
16
votes
4 answers

PercentRelativeLayout inside ScrollView

I have created a layout using a ScrollView which has a PercentRelativeLayout as its child. It doesn't work on Lollipop and older devices but works fine on Marshmallow devices. Please check the code below:
15
votes
4 answers

How to use layout_aspectRatio in the PercentRelativeLayout?

I try to achieve a 16:9 aspect ratio on a view with the PercentRelativeLayout. So I have put this line in my build.gradle file: compile 'com.android.support:design:23.0.1' I use this layout:
6
votes
5 answers

Center a LinearLayout and "percentage" margins

Edit: I have received already two comprehensive answers regarding fixed margins. While I've decided altogether to use fixed margins instead of weight margins, the original question remains open. I am trying to obtain the following design in…
4
votes
3 answers

PercentRelativeLayout 23.2.1 inside ScrollView incorrect zero height

I have a layout that contains a ScrollView with a LinearLayout and its children: a PercentRelativeLayout 23.2.1, another LinearLayout below it and another PercentRelativeLayout after that. Inside the middle LinearLayout I have a RecyclerView…
4
votes
2 answers

How to use PercenRelativeLayout for listView item

I'm trying to use PercenRelativeLayout into ListView, but it doesnot works, height and width percents are ignored and nothing were showing into the listview. it works only for marshmallows. here is list item xml
Jemo Mgebrishvili
  • 5,187
  • 7
  • 38
  • 63
3
votes
0 answers

Android PercentRelativeLayout `aspectRatio` and Implicit Height

I would like to position one image on top of another while still preserving aspect ratio. Here's what I currently have.
0xcaff
  • 13,085
  • 5
  • 47
  • 55
3
votes
1 answer

Android rendering problems, Percent layout

I'm trying to implement the percent relative layout, and I'm following this tutorial: https://blog.stylingandroid.com/percent-part-1/ There doesn't seem to be any errors in my code, but there's still no preview, and it says: "Rendering…
3
votes
0 answers

PercentRelativeLayout childs height is 0

I made a custom view which works fine, but when I place the view inside a PercentRelativeLayout the getHeight() method returns 0, Im not initializing the layout_height or layout_width parameters for the view, only the app:layout_hieghtPercent and …
2
votes
3 answers

ConstraintLayout make View Height x % of Sibling

I was wondering if it's possible with Constraintlayout to achieve the following: I have an Image with a fixed Ratio (2:1) and want it to overlay with a gradient, which should start from the bottom of the Image and top align it to 50% of the Image…
2
votes
0 answers
2
votes
1 answer

Using PercentRelativeLayout specifying only width (heigh auto)

It is possible to use PercentRelativeLayout specifying only the desired width dimension and getting automatic heigh? I mean doing this:
2
votes
1 answer

Use dp width in PercentRelativeLayout

When I try to add a view without "widthPercent" or "heightPercent" in a PercentRelativeLayout, the view doesn't show up. The reason why I want this is to add a divider between the 2 elements of my PercentRelativeLayout with a width of 1dp. The…
MHogge
  • 5,408
  • 15
  • 61
  • 104
2
votes
1 answer

How to use PercentRelativeLayout in a CollapsingToolbarLayout?

I would like to use PercentRelativeLayout throughout my projects, and have been able to do so successfully with Views that don't require scrolling. When using ScrollView's however, attributes such as layout_heightPercent and layout_marginTopPercent…
2
votes
1 answer

Set PercentRelativeLayout percentage in Java

I want to change the width percentage of items inside a PercentRelativeLayoutdynamically in Java based on some events, I found this, but I cannot find where to put the percentages: mLinerLayout.setLayoutParams(new…
Vlad
  • 988
  • 12
  • 18
1
2 3 4