Home > Blockchain >  Android XML Layout Padding Error: activity_horizontal/vertical_margin
Android XML Layout Padding Error: activity_horizontal/vertical_margin

Time:12-18

Hi my xml android code is having an error, I have searched already and can't find any info. Im trying to set layout padding to activity horizontal/vertical margin but its all red. Please help thanks.

<?xml version="1.0" encoding="utf-8"?>
<androidx.gridlayout.widget.GridLayout 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:id="@ id/gridLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="activity_horizontal_margin"
    android:paddingTop="activity_vertical_margin" 
    android:paddingRight="activity_horizontal_margin" 
    android:paddingBottom="activity_vertical_margin" 
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

</androidx.gridlayout.widget.GridLayout>

CodePudding user response:

just remove "androidx.gridlayout.widget." and use "<GridLayout" instead of "<androidx.gridlayout.widget.GridLayout"

or add this dependency for using androidx gridlayout

implementation 'androidx.gridlayout:gridlayout:1.0.0'

CodePudding user response:

It seems like activity_horizontal_margin is not defined anywhere that's why you are getting this error. one of the solution can be.

  1. add in App level build gradle:

    implementation 'com.intuit.ssp:ssp-android:1.0.6'
    implementation 'com.intuit.sdp:sdp-android:1.0.6'
    
  2. and then give padding like this:

    android:paddingLeft="@dimen/activity_horizontal_margin"
    

CodePudding user response:

You are doing it wrong , padding attributes either takes values like 4dp,8dp etc or a reference to a resource file where you store the values.

If you want to use a reference to dimensions just right click on values directory and chose New -> Value Resource File , name it dimen and hit ok

After that add these in the file :

<dimen name="activity_horizontal_margin">16dp</dimen>   //change dimensions to your preference
<dimen name="activity_vertical_margin">16dp</dimen>

And then change padding attributes to this :

android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingBottom="@dimen/activity_vertical_margin"
  • Related