joachim
joachim

Reputation: 692

Box in a Layout

Okay problem first, I have a background image which has some kind of border that has to match a given layout.

My current approach was to to box in a layout, maybe there is a completely different solution.

So 15% margin left&right, 10% margin bottom&top, I already have the left and right margin, the code below, but I'm struggling too also fit the top and bottom margin in the same layout.

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <RelativeLayout
      android:layout_width="0dip"
      android:layout_height="fill_parent"
      android:layout_weight="0.15" />
  <RelativeLayout
      android:layout_width="0dip"
      android:layout_height="fill_parent"
      android:layout_weight="0.7">
      <LinearLayout
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
          <Button
              android:text="Button1 "
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:id="@+id/btn1" />   
          <Button
              android:text="Button2 "
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:id="@+id/btn2" />     
          <Button
              android:text="Button3"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:id="@+id/btn3" />                
      </LinearLayout>
  </RelativeLayout>
  <RelativeLayout
      android:layout_width="0dip"
      android:layout_height="fill_parent"
      android:layout_weight="0.15" />
</LinearLayout>

Upvotes: 0

Views: 46

Answers (1)

user5543258
user5543258

Reputation:

You can use PercentRelativeLayout for percentage sizes, like this

<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.PercentRelativeLayout>

Upvotes: 2

Related Questions