Reputation: 5709
How would I go about changing the orientation of the text in my buttons, so that they are written vertically rather than horizontally?
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.10"
android:text="Previous" />
Is it possible?
Upvotes: 1
Views: 6188
Reputation: 20155
This is the screenshot after setting the width to 12dp
Try this
place \n
character in your string for line breaks in your Strings.xml
like this
1\n 2\n 3\n
and you can directly set it like this
android:text="@String/yourstring"
Upvotes: 7
Reputation: 5709
I fixed it myself. I made a separate folder called layout-land and put a separate XML file in there to take care of that. Now the layout looks fine in both, and I can use hardcoded weights for attributes.
Upvotes: 0
Reputation: 2605
Tried and tested this one it's working absolutely fine.
public class buttonCustom extends Button{
String s="";
public buttonCustom(Context context) {
super(context);
}
public buttonCustom(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public buttonCustom(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
public void setText(CharSequence text, BufferType type) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
for(int i=0;i<text.length();i++)
{
if(s==null)
s="";
s= s+String.valueOf(text.charAt(i))+ "\n";
}
super.setText(s, type);
}
}
Override button class and override the setText function
Upvotes: 2