Ich werde ein Layout mit einer Statusleiste auf der rechten SeiteWie richtet man ein gedrehtes Layout nach rechts aus und passt es der übergeordneten Höhe an?
Ich habe versucht, XML zu verwenden, aber das ist nicht funktionieren, kann die Leiste nicht nach rechts ausrichten, und die Textansicht ist nicht im relativen Layout nach der Drehung.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="test.com.myapplication.MainActivity">
<RelativeLayout
android:id="@+id/top_bar_land"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:rotation="90"
android:background="@android:color/holo_red_light">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
</RelativeLayout>
So Drehung ich es programmatisch
topBarLand = (RelativeLayout) findViewById(R.id.top_bar_land);
ViewTreeObserver vto = topBarLand.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int w = topBarLand.getWidth();
int h = topBarLand.getHeight();
topBarLand.setRotation(90f);
topBarLand.setTranslationX((w - h)/2);
topBarLand.setTranslationY(Math.abs(h - w)/2);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
topBarLand.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
topBarLand.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});
Aber die Breite der Bar können die Höhe des Bildschirms nicht überein
Auch stelle ich eine große Anzahl zu seinem mit, die Breite ändert sich immer noch nicht.
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(1920, h);
topBarLand.setLayoutParams(param);
Wie kann ich die Balkenbreite gleich der Bildschirmhöhe einstellen?
Kumpel, dass rote Farbe Ansicht nehmen Breite nur, weil, wenn es horizontal fill_parent nehmen, wenn Sie 90'c drehen, nimmt es die gleiche Höhe (i bedeutet, dass die Breite aus der Höhe genommen wird) – Vadivel
Standardmäßig rotiert Android mit dem Mittelpunkt der Ansicht als Drehpunkt. Sie können 'transformPivotX' und' transformPivotY' verwenden, um manuelle Rotation zu vermeiden. Vielleicht ist es jedoch eine Möglichkeit, anstelle einer Rotation eine vertikale Textansicht zu wählen. –