android - Set margin to "standalone" view -


this might bad practice, android gui keeps frustrating me always. have standalone view called primary_button under res/layout:

<?xml version="1.0" encoding="utf-8"?> <button xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="wrap_content" android:layout_height="wrap_content"     android:background="@drawable/primary_button"     android:textcolor="@color/light_warm_gray"/> 

and custom background "primary_button" shape under res/drawable:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle">    <solid android:color="@color/light_olive" />    <corners android:radius="10dp"/>    <size android:height="40dp" android:width="40dp" /> </shape> 

now problem is, when set layout_margin 10dp, nothing set because @ point when inflate using line:

button b = (button)view.inflate(this, r.layout.primary_button, null); 

it has no layout parent (obviously needs set layout params). want neat code, , setting *layout.layoutparams in code time pain.

shape padding, , button padding, didn't wanted, intended do. (in case enlarged button shape)

another way thought of, set zero-alpha stroke around it, horrible solution.

i wonder how stock buttons handle this. mean leave nice margin between them (around 15dp?) without having set layout params. shouldn't somehow happen custom view well?

try following:

view.inflate(this, r.layout.primary_button, parentview); 

i suppose there add view method called later. try both keeping , removing it.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -