2017-07-07 4 views
0

Mein Problem mit ListviewListview-Interferenz mit AppBarLayout

Listview-Interferenz mit AppBarLayout

Ich möchte unter der Seite AppBarLayout

progressbar in Zentrum

problem screenshot

Wie App sein bar Titel und Zurück-Taste nach rechts?

activity_category.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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/activity_category" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
tools:context="com.sokhanak.CategoryActivity"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="56dp" 
     android:background="?attr/colorPrimary" /> 

</android.support.design.widget.AppBarLayout> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <android.support.v4.widget.ContentLoadingProgressBar 
     android:id="@+id/progress" 
     style="?android:attr/progressBarStyleLarge" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal|center_vertical" 
     android:visibility="visible" /> 

    <ListView 
     android:id="@+id/listView" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
</FrameLayout> 
</LinearLayout> 

CategoryActivity.java

package com.example; 

import android.content.Intent; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.support.annotation.Nullable; 
import android.support.design.widget.Snackbar; 
import android.support.v4.widget.ContentLoadingProgressBar; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.util.Log; 
import android.view.View; 
import android.view.WindowManager; 
import android.widget.AbsListView; 
import android.widget.AdapterView; 
import android.widget.ListView; 
import android.widget.Toast; 

import com.example.adapter.QuoteArrayAdapter; 
import com.example.model.QuoteDataModel; 
import com.example.parser.JSONParser; 
import com.example.utils.Keys; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

import java.util.ArrayList; 

public class CategoryActivity extends AppCompatActivity { 

    private Toolbar toolbar; 
    private ListView listView; 
    private ArrayList<QuoteDataModel> list; 
    private QuoteArrayAdapter adapter; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_category); 

     Intent i = getIntent(); 
     final String categoryId = i.getStringExtra("categoryId"); 
     String categoryName = i.getStringExtra("categoryName"); 

     toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
     setTitle(categoryName); 

     /** 
     * Array List for Binding Data from JSON to this List 
     */ 
     list = new ArrayList<>(); 

     adapter = new QuoteArrayAdapter(this, list); 

     /** 
     * Getting List and Setting List Adapter 
     */ 
     listView = (ListView) findViewById(R.id.listView); 
     listView.setAdapter(adapter); 
     listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       Snackbar.make(findViewById(R.id.parentLayout), list.get(position).getProfileName() + " => " + list.get(position).getQuoteLike(), Snackbar.LENGTH_LONG).show(); 
      } 
     }); 

     /** 
     * Check internet connection 
     */ 
     if (!MainActivity.NetworkUtil.isOnline(getApplicationContext())) { 
      Toast.makeText(CategoryActivity.this, "اتصال به اینترنت برقرار نیست", 
        Toast.LENGTH_LONG).show(); 
     } 

     new GetDataCategory().execute(categoryId); 

     listView.setOnScrollListener(new AbsListView.OnScrollListener() { 

      public void onScrollStateChanged(AbsListView view, int scrollState) { 


      } 

      public void onScroll(AbsListView view, int firstVisibleItem, 
           int visibleItemCount, int totalItemCount) { 

       if(firstVisibleItem+visibleItemCount == totalItemCount && totalItemCount!=0) 
       { 
        new GetDataCategory().execute(categoryId); 
       } 
      } 
     }); 

     // screen turn on ever 
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 

    } 

/* */ 
} 
+0

Wenn Sie relativelayout Sie müssen Position t er wackelt relativ zueinander. – Juan

Antwort

0

Ändern Sie Ihr Relative Layout Linear-Layout mit Vertikale Ausrichtung

+0

Bitte bearbeiten Layout-Code, Mein erstes Projekt ist Android – user8215914

+0

Überprüfen Sie, dass ich Ihren Layout-Code bearbeitet habe. –

+0

Danke. Nur progressbar auf top listview, ich möchte Center-Seite – user8215914

0
/**Make a change in your listview**/ 

    ListView Interference with AppBarLayout: 


    <ListView 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    android:id="@+id/listView" 
    android:layout_below="@+id/toolbar" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" /> 


    App bar Title and back button to Right: 

    Just add below line inside application tag in AndroidManifestFile 

    android:supportsRtl="true" 
+0

Funktioniert nicht android: layout_below = "@ + id/toolbar" | android: supportsRtl = "true" Kein Effekt – user8215914

0
For putting list below app bar you need to update listview layout with below app bar. 
    Here is the updated code. 

    <?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/activity_category" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context="com.sokhanak.CategoryActivity" 
     > 
     <android.support.design.widget.AppBarLayout 
      android:id="@+id/appBarLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="56dp" 
       android:background="?attr/colorPrimary" 
       /> 

     </android.support.design.widget.AppBarLayout> 

     <android.support.v4.widget.ContentLoadingProgressBar 
      android:id="@+id/progress" 
      style="?android:attr/progressBarStyleLarge" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:visibility="visible" /> 

     <ListView app:layout_behavior="@string/appbar_scrolling_view_behavior" 
      android:id="@+id/listView" 
      android:layout_below="@+id/appBarLayout" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" /> 

    </RelativeLayout> 
Verwandte Themen