我试图实施旋转progressBar
,但无论我尝试什么,它都不会出现。这是xml:
<android.support.v4.widget.DrawerLayout 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/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
tools:context="com.example.home.quoteapp.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@color/background">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/rectangle">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/search"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="10dp"
android:layout_marginTop="18dp"
android:background="@drawable/ic_search_black_24dp"
android:clickable="true"
android:focusable="true"
android:gravity="center" />
<Button
android:id="@+id/back_arrow_search"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginTop="18dp"
android:background="@drawable/ic_arrow_back_black_24dp"
android:clickable="true"
android:focusable="true"
android:visibility="invisible" />
<Button
android:id="@+id/nav_button"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginTop="18dp"
android:background="@drawable/ic_more_vert_black_24dp"
android:clickable="true"
android:focusable="true" />
<EditText
android:id="@+id/section"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_toEndOf="@+id/nav_button"
android:layout_toRightOf="@+id/nav_button"
android:background="@android:color/transparent"
android:clickable="false"
android:ems="10"
android:focusable="false"
android:gravity="left"
android:inputType="textMultiLine|textNoSuggestions"
android:maxHeight="140dp"
android:scrollbars="vertical"
android:text="@string/section"
android:textColor="@color/textColor"
android:textSize="20sp" />
<EditText
android:id="@+id/searchText"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/section"
android:layout_alignBottom="@+id/section"
android:layout_alignStart="@+id/section"
android:background="@drawable/underline"
android:ems="10"
android:hint="Search"
android:imeOptions="actionSearch"
android:inputType="textMultiLine|textNoSuggestions|text"
android:maxHeight="140dp"
android:textColor="@color/textColor"
android:textColorHint="@color/textHint"
android:textCursorDrawable="@null"
android:textSize="20sp"
android:visibility="invisible" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:id="@+id/progressBarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="visible" />
</RelativeLayout>
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:alwaysDrawnWithCache="true"
android:clipChildren="true"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="auto_fit"
android:padding="0dp"
android:scrollingCache="true"
android:smoothScrollbar="true"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp"></GridView>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navView"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/headerColour"
android:theme="@style/NavigationTheme"
android:visibility="invisible"
app:itemBackground="@drawable/nav_item_background"
app:itemTextColor="@color/headerColourAccent"
app:menu="@menu/menu">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:background="@color/headerColourAccent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left"
android:gravity="left"
android:paddingLeft="15dp"
android:paddingTop="15dp"
android:text="Sections"
android:textColor="@color/headerColour"
android:textSize="30dp" />
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
这就是我在MainActivity
的{{1}}中所说的。
progressBar
然后我会通过这样做来使private RelativeLayout progressBarLayout;
private ProgressBar progressBar
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
progressBarLayout = findViewById(R.id.progressBarLayout);
progressBar = findViewById(R.id.progressBar);
progressBar.getIndeterminateDrawable().setColorFilter(0xF09D00, PorterDuff.Mode.MULTIPLY);
}
消失
progressBar
但progressBarLayout.setVisibility(View.GONE);
从未显示过,当我将progressBar
设置为可见性时,它会消失。
答案 0 :(得分:2)
问题出在您的布局层次结构中。我做了一些改变。
根目录为RelativeLayout
,其中包含DrawerLayout
,Progressbar
已移除DrawerLayout
之外,现在位于DrawerLayout
下方的根布局内。另外AppBarLayout
占据了整个屏幕的宽度和高度,我猜这不是你想要的,所以它改为了,因为它阻挡了它下面的其他视图
这是一个工作布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Drawer related content below here-->
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top">
<Button
android:id="@+id/search"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="10dp"
android:layout_marginTop="18dp"
android:clickable="true"
android:focusable="true"
android:gravity="center" />
<Button
android:id="@+id/back_arrow_search"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginTop="18dp"
android:clickable="true"
android:focusable="true"
android:visibility="invisible" />
<Button
android:id="@+id/nav_button"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginTop="18dp"
android:clickable="true"
android:focusable="true" />
<EditText
android:id="@+id/section"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_toEndOf="@+id/nav_button"
android:layout_toRightOf="@+id/nav_button"
android:background="@android:color/transparent"
android:clickable="false"
android:ems="10"
android:focusable="false"
android:gravity="left"
android:inputType="textMultiLine|textNoSuggestions"
android:maxHeight="140dp"
android:scrollbars="vertical"
android:textSize="20sp" />
<EditText
android:id="@+id/searchText"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/section"
android:layout_alignBottom="@+id/section"
android:layout_alignStart="@+id/section"
android:ems="10"
android:hint="Search"
android:imeOptions="actionSearch"
android:inputType="textMultiLine|textNoSuggestions|text"
android:maxHeight="140dp"
android:textCursorDrawable="@null"
android:textSize="20sp"
android:visibility="invisible" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/progressBarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:alwaysDrawnWithCache="true"
android:clipChildren="true"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="auto_fit"
android:padding="0dp"
android:scrollingCache="true"
android:smoothScrollbar="true"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp" />
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navView"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:visibility="invisible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left"
android:gravity="left"
android:paddingLeft="15dp"
android:paddingTop="15dp"
android:text="Sections"
android:textSize="30dp" />
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:indeterminate="true" />
</RelativeLayout>
答案 1 :(得分:0)
在您的ProgressBar中添加这样的大小:
android:maxHeight="20dp"
android:maxWidth="20dp"
android:minHeight="20dp"
android:minWidth="20dp"