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?
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"
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.