Ich verwende ConstraintLayout, um die Seite anzuzeigen, und ich finde den Weg nicht, den Titel in der Mitte der Leiste zu machen. Ich habe die Aktionsleiste oder die Werkzeugleiste nicht benutzt. Bei der Lösung, die ich online gefunden habe, geht es darum, ein Label auf einem aktiven Balken hinzuzufügen, das ich nicht habe. HierSo zentrieren Sie den Seitentitel in ConstraintLayout
ist das Layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_centerHorizontal="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
tools:context="com.spydertrap.occexample.MainActivity"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline2"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="206dp" />
<android.support.v7.widget.CardView
android:id="@+id/cardView2"
android:layout_height="150dp"
android:layout_width="0dp"
app:layout_constraintRight_toLeftOf="@+id/guideline2"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/cardView"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp">
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:layout_marginBottom="50dp"
app:srcCompat="@drawable/resource" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="116dp"
android:layout_marginLeft="10dp"
android:textAppearance="@style/CardSubTitle"
android:text="Resource Center" />
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
und die Aktivität ist ziemlich einfach:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("Dashboard");
}
}
This title needs to be centered
jede mögliche Hilfe geschätzt wird !!
Sie sagen, dass u nicht Aktionsleiste oder die Symbolleiste verwenden, dann, wie u, das hier nicht in Ihrem Layout sehen es einstellen? – Pavan
Ich habe es nicht in meinem Layout festgelegt. Ich habe nur den Titelinhalt in der Aktivität festgelegt. –
dann ist es Action-Bar Sie verwenden Action Bar Thema – Pavan