android - dynamic xml layout rotation -
i have 2 buttons on main activity , when pressed want call exact same activity exept on 1 layout rotated 180 degrees. there way (like rotate based on passed main activity) need create 2 different activities practically same code in respective java file?
edit: when exact same activity don't mean same main. it's same 2 buttons...
i think found solution you. use custom reverse view wraper reverse whole layout.
try run sample code below.
public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); int layoutid = r.layout.main; view content = getlayoutinflater().inflate(layoutid, null); reverseview wraper = new reverseview(this); wraper.addview(content); setcontentview(wraper); } public class reverseview extends framelayout { public reverseview(context context) { super(context); } @override protected void dispatchdraw(canvas canvas) { canvas.save(); int px = getwidth() / 2; int py = getheight() / 2; canvas.rotate(180, px, py); super.dispatchdraw(canvas); canvas.restore(); } } }
Comments
Post a Comment