我正确地居中,正如您在查看content_main.xml设计标签时所看到的那样,
但是,当你看到activity_main.xml设计时,操作栏就位,当它仍然在应用程序的中心时,它不在空白中心,这是我更喜欢的。有关如何计算操作栏的任何建议?如果可能,最好在XML中。
这是我的XML
var data = [{ known_technologies : ["prepaid billing", " postpaid billing"],company : "A",YearsOfExp:0},
{ known_technologies : ["prepaid billing", " postpaid billing"],company:"B",YearsOfExp:1}];
答案 0 :(得分:0)
xml对我有用:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/voting_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical|center"
android:background="@color/colorFaded"
android:configChanges="orientation|screenSize"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:screenOrientation="nosensor"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.gesslar.threshvote.MainActivity"
tools:showIn="@layout/activity_main">
<TextView
android:id="@+id/textStatusMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/colorText" />
<ImageButton
android:id="@+id/buttonVote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:clickable="false"
android:contentDescription="@string/desc_vote_button"
android:onClick="onVotePressed"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:scaleType="fitCenter"
android:src="@drawable/ic_vote_button_image" />
<TextSwitcher
android:id="@+id/textCountdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/buttonVote"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:includeFontPadding="false"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/colorText"
android:textSize="@dimen/countdown" />
<ProgressBar
android:id="@+id/loadingBar"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/textCountdown"
android:layout_gravity="end"
android:indeterminate="true"
android:visibility="invisible" />
</RelativeLayout>
但是你需要在设备或模拟器上运行它。 Android Studio预览显示错误。关键是app:layout_behavior="@string/appbar_scrolling_view_behavior"
修改强>
您还需要使用RelativeLayout
- 它支持父级的良好居中。在LinearLayout
中,只有当ImageView
为match_parent。