Reputation: 3112
I work with Android daily, and I would like to avoid the specifications of the views size.
For example, if I make a TextView
, I got to assign Height and Width properties, like this:
<TextView
android:id="@+id/activity_lbl"
android:layout_width="wrap_content" <!-- Again -->
android:layout_height="wrap_content" <!--Again... --> />
<TextView
android:id="@+id/activity_lbl2"
android:layout_width="wrap_content" <!-- Again... -->
android:layout_height="wrap_content" <!--Again, for ever --> />
And for every view I create, I got to assign the same size specifications. Is there a way to avoid them?
Upvotes: 2
Views: 95
Reputation: 15
you can't avoid the
android:layout_width="wrap_content"
android:layout_height="wrap_content"
because it's important but i'm going to give you some codes for some layouts for images you can use this in your class:
ImageView.getLayoutParams().height = YourHeightValue ;
ImageView.getLayoutParams().width = YourWidthValue;
for the textView use the Textview.setSize(); or TextView.setwidth(int); TextView.setHeight(int);
Upvotes: -2
Reputation: 17922
Declare it within a style that you'll apply in your layout files like this:
File: res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="wrapall">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
</resources>
And then apply it to your layouts like this:
<TextView
android:id="@+id/activity_lbl"
style="@style/wrapall" />
<TextView
android:id="@+id/activity_lbl2"
style="@style/wrapall" />
Upvotes: 5