PercentRelativeLayout
public
class
PercentRelativeLayout
extends RelativeLayout
This class is deprecated.
consider using ConstraintLayout and associated layouts instead. The following shows
how to replicate the functionality of percentage layouts with a ConstraintLayout. The Guidelines
are used to define each percentage break point, and then a Button view is stretched to fill
the gap:
<androidx.constraintlayout.widget.ConstraintLayout
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">
<androidx.constraintlayout.widget.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/left_guideline"
app:layout_constraintGuide_percent=".15"
android:orientation="vertical"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/right_guideline"
app:layout_constraintGuide_percent=".85"
android:orientation="vertical"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/top_guideline"
app:layout_constraintGuide_percent=".15"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bottom_guideline"
app:layout_constraintGuide_percent=".85"
android:orientation="horizontal"/>
<Button
android:text="Button"
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/button"
app:layout_constraintLeft_toLeftOf="@+id/left_guideline"
app:layout_constraintRight_toRightOf="@+id/right_guideline"
app:layout_constraintTop_toTopOf="@+id/top_guideline"
app:layout_constraintBottom_toBottomOf="@+id/bottom_guideline" />
</androidx.constraintlayout.widget.ConstraintLayout>
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. Follow
this example:
<androidx.percentlayout.widget.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%"/>
</androidx.percentlayout.widget.PercentRelativeLayout>
The attributes that you can use are:
layout_widthPercent
layout_heightPercent
layout_marginPercent
layout_marginLeftPercent
layout_marginTopPercent
layout_marginRightPercent
layout_marginBottomPercent
layout_marginStartPercent
layout_marginEndPercent
layout_aspectRatio
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.
You can also make one dimension be a fraction of the other by setting only width or height and
using layout_aspectRatio for the second one to be calculated automatically. For
example, if you would like to achieve 16:9 aspect ratio, you can write:
android:layout_width="300dp"
app:layout_aspectRatio="178%"
This will make the aspect ratio 16:9 (1.78:1) with the width fixed at 300dp and height adjusted
accordingly.
Summary
Nested classes |
class |
PercentRelativeLayout.LayoutParams
This class is deprecated.
this class is deprecated along with its parent class.
|
Inherited constants |
From class
android.widget.RelativeLayout
int |
ABOVE
|
int |
ALIGN_BASELINE
|
int |
ALIGN_BOTTOM
|
int |
ALIGN_END
|
int |
ALIGN_LEFT
|
int |
ALIGN_PARENT_BOTTOM
|
int |
ALIGN_PARENT_END
|
int |
ALIGN_PARENT_LEFT
|
int |
ALIGN_PARENT_RIGHT
|
int |
ALIGN_PARENT_START
|
int |
ALIGN_PARENT_TOP
|
int |
ALIGN_RIGHT
|
int |
ALIGN_START
|
int |
ALIGN_TOP
|
int |
BELOW
|
int |
CENTER_HORIZONTAL
|
int |
CENTER_IN_PARENT
|
int |
CENTER_VERTICAL
|
int |
END_OF
|
int |
LEFT_OF
|
int |
RIGHT_OF
|
int |
START_OF
|
int |
TRUE
|
|
From class
android.view.ViewGroup
int |
CLIP_TO_PADDING_MASK
|
int |
FOCUS_AFTER_DESCENDANTS
|
int |
FOCUS_BEFORE_DESCENDANTS
|
int |
FOCUS_BLOCK_DESCENDANTS
|
int |
LAYOUT_MODE_CLIP_BOUNDS
|
int |
LAYOUT_MODE_OPTICAL_BOUNDS
|
int |
PERSISTENT_ALL_CACHES
|
int |
PERSISTENT_ANIMATION_CACHE
|
int |
PERSISTENT_NO_CACHE
|
int |
PERSISTENT_SCROLLING_CACHE
|
|
From class
android.view.View
int |
ACCESSIBILITY_LIVE_REGION_ASSERTIVE
|
int |
ACCESSIBILITY_LIVE_REGION_NONE
|
int |
ACCESSIBILITY_LIVE_REGION_POLITE
|
int |
AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
|
String |
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE
|
String |
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY
|
String |
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH
|
String |
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR
|
String |
AUTOFILL_HINT_CREDIT_CARD_NUMBER
|
String |
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE
|
String |
AUTOFILL_HINT_EMAIL_ADDRESS
|
String |
AUTOFILL_HINT_NAME
|
String |
AUTOFILL_HINT_PASSWORD
|
String |
AUTOFILL_HINT_PHONE
|
String |
AUTOFILL_HINT_POSTAL_ADDRESS
|
String |
AUTOFILL_HINT_POSTAL_CODE
|
String |
AUTOFILL_HINT_USERNAME
|
int |
AUTOFILL_TYPE_DATE
|
int |
AUTOFILL_TYPE_LIST
|
int |
AUTOFILL_TYPE_NONE
|
int |
AUTOFILL_TYPE_TEXT
|
int |
AUTOFILL_TYPE_TOGGLE
|
int |
DRAG_FLAG_GLOBAL
|
int |
DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION
|
int |
DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION
|
int |
DRAG_FLAG_GLOBAL_URI_READ
|
int |
DRAG_FLAG_GLOBAL_URI_WRITE
|
int |
DRAG_FLAG_OPAQUE
|
int |
DRAWING_CACHE_QUALITY_AUTO
|
int |
DRAWING_CACHE_QUALITY_HIGH
|
int |
DRAWING_CACHE_QUALITY_LOW
|
int |
FIND_VIEWS_WITH_CONTENT_DESCRIPTION
|
int |
FIND_VIEWS_WITH_TEXT
|
int |
FOCUSABLE
|
int |
FOCUSABLES_ALL
|
int |
FOCUSABLES_TOUCH_MODE
|
int |
FOCUSABLE_AUTO
|
int |
FOCUS_BACKWARD
|
int |
FOCUS_DOWN
|
int |
FOCUS_FORWARD
|
int |
FOCUS_LEFT
|
int |
FOCUS_RIGHT
|
int |
FOCUS_UP
|
int |
GONE
|
int |
HAPTIC_FEEDBACK_ENABLED
|
int |
IMPORTANT_FOR_ACCESSIBILITY_AUTO
|
int |
IMPORTANT_FOR_ACCESSIBILITY_NO
|
int |
IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
|
int |
IMPORTANT_FOR_ACCESSIBILITY_YES
|
int |
IMPORTANT_FOR_AUTOFILL_AUTO
|
int |
IMPORTANT_FOR_AUTOFILL_NO
|
int |
IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS
|
int |
IMPORTANT_FOR_AUTOFILL_YES
|
int |
IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS
|
int |
IMPORTANT_FOR_CONTENT_CAPTURE_AUTO
|
int |
IMPORTANT_FOR_CONTENT_CAPTURE_NO
|
int |
IMPORTANT_FOR_CONTENT_CAPTURE_NO_EXCLUDE_DESCENDANTS
|
int |
IMPORTANT_FOR_CONTENT_CAPTURE_YES
|
int |
IMPORTANT_FOR_CONTENT_CAPTURE_YES_EXCLUDE_DESCENDANTS
|
int |
INVISIBLE
|
int |
KEEP_SCREEN_ON
|
int |
LAYER_TYPE_HARDWARE
|
int |
LAYER_TYPE_NONE
|
int |
LAYER_TYPE_SOFTWARE
|
int |
LAYOUT_DIRECTION_INHERIT
|
int |
LAYOUT_DIRECTION_LOCALE
|
int |
LAYOUT_DIRECTION_LTR
|
int |
LAYOUT_DIRECTION_RTL
|
int |
MEASURED_HEIGHT_STATE_SHIFT
|
int |
MEASURED_SIZE_MASK
|
int |
MEASURED_STATE_MASK
|
int |
MEASURED_STATE_TOO_SMALL
|
int |
NOT_FOCUSABLE
|
int |
NO_ID
|
int |
OVER_SCROLL_ALWAYS
|
int |
OVER_SCROLL_IF_CONTENT_SCROLLS
|
int |
OVER_SCROLL_NEVER
|
int |
SCREEN_STATE_OFF
|
int |
SCREEN_STATE_ON
|
int |
SCROLLBARS_INSIDE_INSET
|
int |
SCROLLBARS_INSIDE_OVERLAY
|
int |
SCROLLBARS_OUTSIDE_INSET
|
int |
SCROLLBARS_OUTSIDE_OVERLAY
|
int |
SCROLLBAR_POSITION_DEFAULT
|
int |
SCROLLBAR_POSITION_LEFT
|
int |
SCROLLBAR_POSITION_RIGHT
|
int |
SCROLL_AXIS_HORIZONTAL
|
int |
SCROLL_AXIS_NONE
|
int |
SCROLL_AXIS_VERTICAL
|
int |
SCROLL_CAPTURE_HINT_AUTO
|
int |
SCROLL_CAPTURE_HINT_EXCLUDE
|
int |
SCROLL_CAPTURE_HINT_EXCLUDE_DESCENDANTS
|
int |
SCROLL_CAPTURE_HINT_INCLUDE
|
int |
SCROLL_INDICATOR_BOTTOM
|
int |
SCROLL_INDICATOR_END
|
int |
SCROLL_INDICATOR_LEFT
|
int |
SCROLL_INDICATOR_RIGHT
|
int |
SCROLL_INDICATOR_START
|
int |
SCROLL_INDICATOR_TOP
|
int |
SOUND_EFFECTS_ENABLED
|
int |
STATUS_BAR_HIDDEN
|
int |
STATUS_BAR_VISIBLE
|
int |
SYSTEM_UI_FLAG_FULLSCREEN
|
int |
SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
int |
SYSTEM_UI_FLAG_IMMERSIVE
|
int |
SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
int |
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
int |
SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
int |
SYSTEM_UI_FLAG_LAYOUT_STABLE
|
int |
SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
int |
SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
int |
SYSTEM_UI_FLAG_LOW_PROFILE
|
int |
SYSTEM_UI_FLAG_VISIBLE
|
int |
SYSTEM_UI_LAYOUT_FLAGS
|
int |
TEXT_ALIGNMENT_CENTER
|
int |
TEXT_ALIGNMENT_GRAVITY
|
int |
TEXT_ALIGNMENT_INHERIT
|
int |
TEXT_ALIGNMENT_TEXT_END
|
int |
TEXT_ALIGNMENT_TEXT_START
|
int |
TEXT_ALIGNMENT_VIEW_END
|
int |
TEXT_ALIGNMENT_VIEW_START
|
int |
TEXT_DIRECTION_ANY_RTL
|
int |
TEXT_DIRECTION_FIRST_STRONG
|
int |
TEXT_DIRECTION_FIRST_STRONG_LTR
|
int |
TEXT_DIRECTION_FIRST_STRONG_RTL
|
int |
TEXT_DIRECTION_INHERIT
|
int |
TEXT_DIRECTION_LOCALE
|
int |
TEXT_DIRECTION_LTR
|
int |
TEXT_DIRECTION_RTL
|
String |
VIEW_LOG_TAG
|
int |
VISIBLE
|
|
Inherited fields |
From class
android.view.View
public
static
final
Property<View, Float> |
ALPHA
|
protected
static
final
int[] |
EMPTY_STATE_SET
|
protected
static
final
int[] |
ENABLED_FOCUSED_SELECTED_STATE_SET
|
protected
static
final
int[] |
ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
|
protected
static
final
int[] |
ENABLED_FOCUSED_STATE_SET
|
protected
static
final
int[] |
ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET
|
protected
static
final
int[] |
ENABLED_SELECTED_STATE_SET
|
protected
static
final
int[] |
ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET
|
protected
static
final
int[] |
ENABLED_STATE_SET
|
protected
static
final
int[] |
ENABLED_WINDOW_FOCUSED_STATE_SET
|
protected
static
final
int[] |
FOCUSED_SELECTED_STATE_SET
|
protected
static
final
int[] |
FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
|
protected
static
final
int[] |
FOCUSED_STATE_SET
|
protected
static
final
int[] |
FOCUSED_WINDOW_FOCUSED_STATE_SET
|
protected
static
final
int[] |
PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET
|
protected
static
final
int[] |
PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
|
protected
static
final
int[] |
PRESSED_ENABLED_FOCUSED_STATE_SET
|
protected
static
final
int[] |
PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET
|
protected
static
final
int[] |
PRESSED_ENABLED_SELECTED_STATE_SET
|
protected
static
final
int[] |
PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET
|
protected
static
final
int[] |
PRESSED_ENABLED_STATE_SET
|
protected
static
final
int[] |
PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET
|
protected
static
final
int[] |
PRESSED_FOCUSED_SELECTED_STATE_SET
|
protected
static
final
int[] |
PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
|
protected
static
final
int[] |
PRESSED_FOCUSED_STATE_SET
|
protected
static
final
int[] |
PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET
|
protected
static
final
int[] |
PRESSED_SELECTED_STATE_SET
|
protected
static
final
int[] |
PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET
|
protected
static
final
int[] |
PRESSED_STATE_SET
|
protected
static
final
int[] |
PRESSED_WINDOW_FOCUSED_STATE_SET
|
public
static
final
Property<View, Float> |
ROTATION
|
public
static
final
Property<View, Float> |
ROTATION_X
|
public
static
final
Property<View, Float> |
ROTATION_Y
|
public
static
final
Property<View, Float> |
SCALE_X
|
public
static
final
Property<View, Float> |
SCALE_Y
|
protected
static
final
int[] |
SELECTED_STATE_SET
|
protected
static
final
int[] |
SELECTED_WINDOW_FOCUSED_STATE_SET
|
public
static
final
Property<View, Float> |
TRANSLATION_X
|
| <code translate="
| |