I'm building an Android app.
In my first activity I want to create a list of button like this:
So I have build this code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#e3e3e3"
android:gravity="center_horizontal"
android:baselineAligned="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginTop="15dp"
>
<ImageButton
android:id="#+id/ButtonArticoli"
android:layout_width="150px"
android:layout_height="150px"
android:onClick="visualizzaArticoli"
android:scaleType="fitCenter"
android:src="#drawable/articoli"
/>
<TextView
android:id="#+id/textViewArticoli"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/articoli"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200px"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginTop="15dp"
>
<ImageButton
android:id="#+id/ImageButtonCreateOrder"
android:layout_width="150px"
android:layout_height="150px"
android:onClick="creaOrdine"
android:src="#drawable/order"/>
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/ordini"
android:gravity="center" />
</LinearLayout>
<!-- Prima Riga -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200px"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginTop="15dp"
>
<ImageButton
android:id="#+id/ImageButtonClienti"
android:layout_width="150px"
android:layout_height="150px"
android:onClick="viewClienti"
android:scaleType="fitCenter"
android:src="#drawable/customer"/>
<TextView
android:id="#+id/textView23"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/cliente"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200px"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginTop="15dp"
>
<ImageButton
android:id="#+id/ImageButtonAlignDatabase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="allineaDatase"
android:scaleType="fitCenter"
android:src="#drawable/sincronizza"/>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/allinea_database"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200px"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginTop="15dp"
>
<ImageButton
android:id="#+id/ImageButtonSetting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="setting"
android:scaleType="fitCenter"
android:src="#drawable/setting"/>
<TextView
android:id="#+id/TextView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/impostazioni"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
But the result of my app when I try yo start my application is this:
Can we help me?
Use this code if you have a fixed size of elements.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#F1C983">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
card_view:cardBackgroundColor="#D9EE9A">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:background="#null"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sample Text"
android:layout_gravity="center_vertical"
android:layout_marginLeft="50dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
card_view:cardBackgroundColor="#D9EE9A">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:background="#null"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sample Text"
android:layout_gravity="center_vertical"
android:layout_marginLeft="50dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
card_view:cardBackgroundColor="#D9EE9A">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:background="#null"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sample Text"
android:layout_gravity="center_vertical"
android:layout_marginLeft="50dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
Use compile 'com.android.support:cardview-v7:25.0.0' to get the CardView.
this is the sample output.
use ListView or RecyclerView with your custom list item which will contain image buttons and custom adapter
Instead of px use dp it´s much better!
If you want a fixed list, your XML is correct, but if you want a dynamic list, you should use ListView or RecycleView , as the others users said.
The weight in your LinearLayout is wrong, weight should be used when you desires your screen to fit in every screen, no matter the size ( and you will need to "distribute" your weigth throught the children´s).
To make your screen similar to the first image, you need to set a background in your second LinearLayout
Okey this a recyclerview for what you want,
public class MainPageAdapter extends RecyclerView.Adapter<MainPageAdapter.ViewHolder> {
private #DrawableRes int[] iconDrawables;
private String[] texts;
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
return new ViewHolder(v);
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.img_lockIcon.setImageResource(iconDrawables[position]);
holder.txt_whatever.setText(texts[position]);
}
#Override
public int getItemCount() {
return iconDrawables != null ? iconDrawables.length : 0;
}
public void setData(#DrawableRes int[] iconDrawables, String[] texts){
this.iconDrawables = iconDrawables;
this.texts = texts;
this.notifyDataSetChanged();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
ImageView img_icon;
TextView txt_whatever;
ImageView img_lockIcon;
public ViewHolder(View itemView) {
super(itemView);
img_icon = itemView.findViewById(R.id.item_img_icon);
txt_whatever = itemView.findViewById(R.id.item_txt_whatever);
img_lockIcon = itemView.findViewById(R.id.item_img_lockIcon);
}
}
}
this is R.layout.item,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:padding="8dp"
android:background="#color/colorAccent"
xmlns:tools="http://schemas.android.com/tools">
<ImageView
android:id="#+id/item_img_icon"
android:layout_width="36dp"
android:layout_height="36dp"
tools:src="#mipmap/ic_launcher"/>
<TextView
android:id="#+id/item_txt_whatever"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:textColor="#android:color/white"
tools:text="YouTube"/>
<ImageView
android:id="#+id/item_img_lockIcon"
android:layout_width="40dp"
android:layout_height="40dp"
tools:src="#mipmap/ic_launcher"/>
</LinearLayout>
and below is MainActivity layout,
<FrameLayout 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_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="0dp"
app:cardElevation="0dp"
app:cardBackgroundColor="#color/colorPrimary"
android:layout_margin="8dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="#layout/item"/>
</android.support.v7.widget.CardView>
</FrameLayout>
and below is MainActivity,
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
MainPageAdapter adapter = new MainPageAdapter();
recyclerView.setAdapter(adapter);
//Set your data
//adapter.setData();
}
}
You can change color as you want and also notify that ı used two different arrays for adapter but you can use pojo classes also. Hope this helps you.
Related
I am making android cv app and I have implemented RecyclerView but items not scrolling even though, I have used RecyclerViewLayout Manager.
below my SkillsAdapter.class
public class SkillsAdapter extends RecyclerView.Adapter {
public List skillList;
public Context context;
public SkillsAdapter(List<Skill> skillList, Context context) {
this.skillList = skillList;
this.context = context;
}
#NonNull
#Override
public SkillsAdapter.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(context)
.inflate(R.layout.skills_item, parent, false); // change
return new SkillsAdapter.ViewHolder(itemView);
}
#Override
public void onBindViewHolder(#NonNull SkillsAdapter.ViewHolder holder, int position) {
Skill skill = skillList.get(position);
holder.programming.setText(skill.getProgramming());
holder.framework.setText(skill.getFrameworkLibraries());
holder.architecture.setText(skill.getAndroidArchitectureComponents());
holder.software.setText(skill.getSoftwareMethodologies());
holder.ide.setText(skill.getIDES());
}
#Override
public int getItemCount() {
return skillList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView programming, framework, architecture, software, ide;
public ViewHolder(View view) {
super(view);
programming= (TextView) view.findViewById(R.id.programming);
framework = (TextView) view.findViewById(R.id.framework);
architecture = (TextView) view.findViewById(R.id.architecture);
software = (TextView) view.findViewById(R.id.software);
ide = (TextView)view.findViewById(R.id.ide);
}
}
}
below my SkillsItem.java class
public class SkillItem extends AppCompatActivity {
private SkillsAdapter skillsAdapter;
public List<Skill> skillList;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.skills);
KitabInterface kitabInterface = ApiClient.getApiService();
Call<KitabSawti> call = kitabInterface.getSkills();
call.enqueue(new Callback<KitabSawti>() {
#Override
public void onResponse(Call<KitabSawti> call, Response<KitabSawti> response) {
skillList= response.body().getSkills();
RecyclerView recyclerView = findViewById(R.id.recyclerView);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
skillsAdapter = new SkillsAdapter( skillList, SkillItem.this); // changes
recyclerView.setAdapter(skillsAdapter);
}
#Override
public void onFailure(Call<KitabSawti> call, Throwable t) {
}
});
}
}
below my skills_items.xml where I have implemented items
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBlust"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorBlust"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<ImageView
android:id="#+id/educationImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:src="#drawable/it_skills"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/education_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:text="#string/text_skills"
android:textColor="#color/colorWhite"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorBlust"
android:orientation="horizontal"
android:padding="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/subjectImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:src="#drawable/programming_skills"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/programming"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="100dp"
android:layout_marginLeft="100dp"
android:text="#string/programming_skills"
android:textColor="#color/colorWhite"
android:textSize="20sp" />
<View style="#style/dividerHorizontal" />
</RelativeLayout>
</LinearLayout>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorBlust"
android:orientation="horizontal"
android:padding="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/framework_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:src="#drawable/it_frameworks"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/framework"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="100dp"
android:layout_marginLeft="100dp"
android:text="#string/text_framework"
android:textColor="#color/colorWhite"
android:textSize="20sp" />
<View style="#style/dividerHorizontal" />
</RelativeLayout>
</LinearLayout>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorBlust"
android:orientation="horizontal"
android:padding="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/android_component"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:src="#drawable/android_components"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/architecture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="100dp"
android:layout_marginLeft="100dp"
android:text="#string/architecture"
android:textColor="#color/colorWhite"
android:textSize="20sp" />
<View style="#style/dividerHorizontal" />
</RelativeLayout>
</LinearLayout>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorBlust"
android:orientation="horizontal"
android:padding="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/software_method"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:src="#drawable/software_methodologies"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/software"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="100dp"
android:layout_marginLeft="100dp"
android:text="#string/software"
android:textColor="#color/colorWhite"
android:textSize="20sp" />
<View style="#style/dividerHorizontal" />
</RelativeLayout>
</LinearLayout>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorBlust"
android:orientation="horizontal"
android:padding="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/software_ide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:src="#drawable/software_ide"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/ide"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="100dp"
android:layout_marginLeft="100dp"
android:text="#string/ides"
android:textColor="#color/colorWhite"
android:textSize="20sp" />
<View style="#style/dividerHorizontal" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
below my skills.xml where I have hosted RecyclerView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</RelativeLayout>
below screenshot
current ui
The problem is, that the root layout of your item (the root LinearLayout at skills_items.xml) has height of match_parent. This messes up the way RecyclerView does the scrolling event calculations.
Also, it is generally advised against using wrap_content for height or width of the root layout for an activity and for wrap_content for height (if scroll is vertical) or width (if scroll is horizontal) of RecyclerView or ListView.
I have a ListView, where i changed appearence of row, but listview have size of one row, instead of fullscreen.
and my scrollview is working but listview is not working.
activity_graph_view.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_graph_table_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="00dp"
android:background="#color/background"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/appbar"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<LinearLayout
android:id="#+id/layoutTableOne"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp"
android:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Table View"
android:textSize="#dimen/subheading"
android:textColor="#color/subheading"
android:textAllCaps="false" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="#+id/lv_spirometer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#color/mdtp_button_selected"
android:dividerHeight="1dp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.9"
android:padding="10dp"
android:text="Graph View"
android:textAllCaps="false"
android:textColor="#color/subheading"
android:textSize="#dimen/subheading" />
</LinearLayout>
<com.jjoe64.graphview.GraphView
android:id="#+id/grapfinal"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
android:weightSum="1">
<LinearLayout
android:id="#+id/grphtextMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/grphtextColor"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginTop="3dp"
android:orientation="vertical" />
<TextView
android:id="#+id/grphtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Hello"
android:textColor="#color/subheading"
android:textSize="14dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/grphtextMain2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/grphtextColor2"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginTop="3dp"
android:background="#color/red_btn_bg_color"
android:orientation="vertical" />
<TextView
android:id="#+id/grphtext2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Hello"
android:textColor="#color/subheading"
android:textSize="14dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.9"
android:padding="10dp"
android:text="Graph View"
android:textAllCaps="false"
android:textColor="#color/subheading"
android:textSize="#dimen/subheading" />
</LinearLayout>
<com.jjoe64.graphview.GraphView
android:id="#+id/grapfinal1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
android:weightSum="1">
<LinearLayout
android:id="#+id/grphtextMain1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/grphtextColor1"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginTop="3dp"
android:background="#color/red_btn_bg_color"
android:orientation="vertical" />
<TextView
android:id="#+id/grphtext1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Hello"
android:textColor="#color/subheading"
android:textSize="14dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
spirometer_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
app:cardBackgroundColor="#fff4f4f3"
app:cardElevation="10dp"
app:cardPreventCornerOverlap="true"
card_view:cardCornerRadius="8dp">
<LinearLayout
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_marginLeft="10dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tv_fvc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FVC 3.15 L" />
<TextView
android:id="#+id/tv_fev1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FEV1 2.44 L" />
<TextView
android:id="#+id/tv_pef"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PEF 3.74 L/s" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
CustomAdapter1.java
public class CustomAdapter1 extends BaseAdapter {
ArrayList<GetUserSpirometer> arrayList;
public CustomAdapter1(ArrayList<GetUserSpirometer> arrayList){
this.arrayList=arrayList;
Log.e("arraylist length",""+arrayList.size());
}
#Override
public int getCount() {
return arrayList.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater= getLayoutInflater();
ViewHolder1 holder=new ViewHolder1();
convertView = inflater.inflate(R.layout.spirometer_item, parent, false);
holder.tv_date=(TextView)convertView.findViewById(R.id.tv_date);
holder.tv_fvc=(TextView)convertView.findViewById(R.id.tv_fvc);
holder.tv_fev1=(TextView)convertView.findViewById(R.id.tv_fev1);
holder.tv_pef=(TextView)convertView.findViewById(R.id.tv_pef);
String[] arr = getDate(Long.parseLong(arrayList.get(position).get_date()), "MMM dd, yyy/hh:mm a").split("/");
holder.tv_date.setText(arr[0] + "\n" + arr[1]);
holder.tv_fvc.setText(arrayList.get(position).get_userfvc());
holder.tv_fev1.setText(arrayList.get(position).get_userfev1());
holder.tv_pef.setText(arrayList.get(position).get_userpef());
convertView.setTag(holder);
return convertView;
}
}
Items are not scrolling.
how to solve this. please help.
thanks in advance.
Then you need to change itemView's xml file ,
android:layout_height="match_parent"
instead of like ,
android:layout_height="wrap_content"
Simple change in spirometer_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
....Your design code
</LinearLayout>
I was having problem with the same from such a long time. Then I found a solution that worked for me.
Add a ListViewHelper java class. Here below is code for ListViewHelper.java
package com.molescope;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
public class ListViewHelper {
public static void getListViewSize(ListView listView){
ListAdapter adapter = listView.getAdapter();
if(adapter!=null){
int totalHeight = 0;
//setting list adapter in loop tp get final size
for (int i=0; i<adapter.getCount(); i++){
View listItem = adapter.getView(i, null, listView);
listItem.measure(0,0);
totalHeight += listItem.getMeasuredHeight();
}
//setting listview items in adapter
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() *
(adapter.getCount()-1));
listView.setLayoutParams(params);
}else{
return;
}
}
}
And after adding this java file, in your code wherever you are setting adapter to listview, right after that line add the code below:
ListView myList=(ListView) findViewById(R.id.listView);
myList.setAdapter(new ArrayAdapter<String>.
(this,android.R.layout.simple_list_item_1, listview_array));
ListViewHelper.getListViewSize(myList);
how can I make a layout that looks like this in android using list view.
I am making a tracking system for many buses. If the bus crossed the location the circle will turn green else it is red.
I just want a vertical line which has length depending on the number of stops for the bus.
the line should be passing through the center of the circles.
Here is the listBusStops.xml file
`
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginBottom="30dp">
<ImageView
android:id="#+id/ivstatus"
android:layout_width="30dp"
android:layout_height="30dp"/>
<TextView
android:layout_marginStart="5dp"
android:gravity="center_vertical"
android:id="#+id/tvname"
android:layout_width="wrap_content"
android:layout_height="30dp"
/>
</TableRow>
</RelativeLayout>
`
here the custom_list class which I am using
`
class Custom_list extends ArrayAdapter {
private final Activity context;
private final Integer imageid;
ArrayList<String> list;
ArrayList<String> status;
public Custom_list(Activity context, ArrayList<String> list, ArrayList<String> status, Integer imageid) {
super(context, R.layout.list_bus_stops,Track_any_bus.stop_name);
this.context=context;
this.list = list;
this.imageid=imageid;
this.status = status;
}
public View getView (int position, View view, ViewGroup parent)
{
LayoutInflater inflater = context.getLayoutInflater();
View rowview = inflater.inflate(R.layout.list_bus_stops,null,true);// ALL LAYOUT RESOURSE OF list_bus_stops SAVED TO THIS VIEW(rowview)
TextView textView = rowview.findViewById(R.id.tvname);//
ImageView imageView = rowview.findViewById(R.id.ivstatus);
textView.setText(Track_any_bus.stop_name.get(position));
if(Track_any_bus.status.get(position).equalsIgnoreCase("yes")) {
imageView.setImageResource(R.drawable.circle_green);
}
else {
imageView.setImageResource(R.drawable.circle_red);
}
return rowview;
}
`
thank you for your time.
Here is the demo working code plz have a look i hope it will help you
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:id="#+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:scrollingCache="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:background="#D3D3D3" />
<ImageView
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginTop="44dp"
android:tint="#000000"
app:srcCompat="#drawable/shape_round_solid" />
</RelativeLayout>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="1dp"
app:cardCornerRadius="5dp"
app:cardElevation="12dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:background="#ffff"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:background="#800000"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_height="1dp"></LinearLayout>
<TextView
android:id="#+id/noteTitle"
android:textColor="#ffffff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
android:background="#000000 "
android:textSize="20dp" />
<LinearLayout
android:layout_width="match_parent"
android:background="#800000"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_height="1dp"></LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:textSize="14dp"
android:textColor="#000080"
android:text="Text-Preview"/>
<TextView
android:id="#+id/textPreview"
android:textSize="14dp"
android:textColor="#000080"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="5dp"
android:text="Sample Text"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_height="wrap_content"
android:textSize="14dp"
android:textColor="#000080"
android:layout_marginLeft="18dp"
android:layout_width="120dp"
android:text="Last Modified"/>
<TextView
android:id="#+id/lastModified"
android:textColor="#000080"
android:layout_width="wrap_content"
android:textSize="14dp"
android:layout_marginLeft="50dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="5dp"
android:text="12/4/2018"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
This is the individual item's layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#DDE6EC"
tools:context="com.example.personal.newsfeeder.MainActivity">
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/section_recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="16dp"
android:id="#+id/card_view"
android:layout_gravity="center"
card_view:cardCornerRadius="8dp"
card_view:cardElevation="10dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/avatar_section"
android:layout_width="match_parent"
android:layout_height="72dp"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#drawable/circular_image"
android:id="#+id/avatar_image"
/>
<TextView
android:id="#+id/avatar_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/avatar_image"
android:layout_marginLeft="4dp"
tools:text="Title"
android:textStyle="bold"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#616161"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/avatar_name"
android:layout_toRightOf="#id/avatar_image"
android:layout_marginLeft="4dp"
tools:text="Subhead"
android:id="#+id/avatar_subhead"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="#616161"/>
</RelativeLayout>
<ImageView
android:layout_height="wrap_content"
android:layout_width="match_parent"
tools:src="#drawable/placeholder"
android:id="#+id/image_view"
android:scaleType="centerCrop"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:text="Keep Moving"
android:paddingLeft="16dp"
android:textAppearance="?android:textAppearanceMedium"
android:textAllCaps="true"
android:textStyle="bold"
android:id="#+id/the_title"
/>f
<TextView
android:id="#+id/the_three_lines"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="3"
android:padding="16dp"
tools:text="#string/description"
android:ellipsize="end"
android:lineSpacingMultiplier="1.2"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/heart_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/heart"
android:padding="8dp"
/>
<ImageView
android:id="#+id/bookmark_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/bookmark"
android:padding="8dp"
/>
</LinearLayout>
</LinearLayout>
enter code here
</android.support.v7.widget.CardView>
</LinearLayout>
This is the recycler's Adapter code
#Override
public void onBindViewHolder(ArticleViewHolder holder, int position) {
holder.mAvatarView.setText(mArticles.get(position).getmAvatarInitial());
holder.mAvatarNameView.setText(mArticles.get(position).getmAvatarName());
holder.mAvatarSubView.setText(mArticles.get(position).getmAvatarSub());
mRowIndex++;
if (position == 0) {
holder.horizontalList.setLayoutManager(new LinearLayoutManager(holder.context, LinearLayoutManager.HORIZONTAL, false));
holder.horizontalAdapter = new SectionRVAdapter(holder.context);
holder.horizontalList.setAdapter(holder.horizontalAdapter);
holder.horizontalAdapter.setDataset(holder.sections);
}
String imageUrl = mArticles.get(position).getmImageURL();
Picasso.with(mContext)
.load(imageUrl)
.placeholder(R.drawable.placeholder)
.error(R.drawable.error_img)
.into(holder.mImageView);
holder.mTheTitleView.setText(mArticles.get(position).getmTheTitle());
holder.mTheThreeLinesView.setText(mArticles.get(position).getmTheThreeLines());
}
Now i want a horizontal recycler view over the vertical recycler view. But at present the horizontal recycler view is repeated after every 5 cardviews.
I am checking if position is equal to 0 in my onBindViewHolder method but still why is it created multiple times?
I hope i made my question clear.
holder.setIsRecyclable(false);
Add this line in public void onBindViewHolder(ArticleViewHolder holder, int position) {}
I hope this will help you
i have a gridview to show images with button, but i have a problem, it only shows the first row, and i send it data for 3 rows..
This is my layout code:
<?xml version="1.0" encoding="utf-8"?><!-- To make screen scroll in vertical direction -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapthumbnail="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#drawable/fondodroid2"
android:orientation="vertical">
<!-- Main layout -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fefdff"
android:layout_marginLeft="#dimen/login_activity_horizontal_margin"
android:layout_marginRight="#dimen/login_activity_horizontal_margin"
android:layout_marginTop="#dimen/login_activity_vertical_margin"
android:padding="#dimen/login_activity_horizontal_margin"
android:id="#+id/linearLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_marginBottom="#dimen/login_activity_vertical_margin"
android:weightSum="1">
<ImageView
android:layout_width="#dimen/login_activity_logo"
android:layout_height="#dimen/login_activity_logo"
android:id="#+id/imageView"
android:src="#drawable/logo"
android:contentDescription="Icon GG"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/files"
android:id="#+id/textView"
android:textSize="#dimen/login_activity_text"
android:textColor="#android:color/black"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView"
android:layout_marginLeft="10dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="#+id/relativeLayout">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:background="#686868"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="#string/sign_string"
android:textSize="#dimen/login_activity_vertical_margin"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/linearSign"
android:layout_centerInParent="true"
android:background="#cccccc"
android:visibility="gone">
<ImageView
android:id="#+id/sign_thumb"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_margin="3dp"></ImageView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="#+id/sign_thumb"
android:layout_alignEnd="#+id/sign_thumb">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eliminar"
android:id="#+id/deleteButton"
android:background="#cc6b67"
android:textStyle="bold"
android:layout_marginBottom="8dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="#+id/relativeLayout2"
android:layout_marginTop="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:background="#686868"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="#string/images"
android:textSize="#dimen/login_activity_vertical_margin"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/linearLayout2">
<GridView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/gridImages"
android:numColumns="2"
android:layerType="hardware"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="#dimen/login_activity_logo_h"
android:layout_height="#dimen/login_activity_logo_v"
android:id="#+id/imageView2"
android:src="#drawable/logo"
android:layout_below="#+id/linearLayout"
android:layout_alignRight="#+id/linearLayout"
android:layout_marginTop="#dimen/login_activity_vertical_margin"
android:layout_marginBottom="#dimen/login_activity_vertical_margin"
android:contentDescription="#string/logo" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
In the adapter i dont have any strangle, but if you need i copy it here..I try with fill_parent wrap_content etc but nothing works..
Edit: the adapter code:
public class GridAdapter extends BaseAdapter {
private LayoutInflater inflater;
private Activity activity;
private List<String> images = new ArrayList<String>();
private OnDeleteItem mListener;
public interface OnDeleteItem {
public void onDeleteItemClick(String path);
}
public GridAdapter(Activity inyectActivity, List<String> listImages) {
activity = inyectActivity;
images = listImages;
inflater = LayoutInflater.from(activity);
mListener = (ReviewFilesActivity) activity;
}
public void notifyDataSetChanged(List<String> dataImages) {
images = dataImages;
super.notifyDataSetChanged();
}
public View getView(final int position, View convertView, ViewGroup parent) {
GridViewHolder vHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.grid_view, null);
vHolder = new GridViewHolder(convertView, mListener);
vHolder.image.setImageBitmap(ImagesUtilities.decodeSampledBitmapFromResource(images.get(position), 400, 400));
vHolder.path = images.get(position);
vHolder.delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mListener.onDeleteItemClick(images.get(position));
}
});
} else {
vHolder = (GridViewHolder) convertView.getTag();
}
return convertView;
}
#Override
public int getCount() {
return images.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
static class GridViewHolder {
public GridViewHolder(View view, OnDeleteItem listener) {
ButterKnife.inject(this, view);
}
#InjectView(R.id.grid_item_image)
ImageView image;
#InjectView(R.id.deleteButton)
Button delete;
String path;
public String getPath() {
return path;
}
}
}
Edit2:
I did more simply the XML, but the rows dont show.
<?xml version="1.0" encoding="utf-8"?><!-- To make screen scroll in vertical direction -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#drawable/fondodroid2"
android:orientation="vertical">
<!-- Main layout -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fefdff"
android:layout_marginLeft="#dimen/login_activity_horizontal_margin"
android:layout_marginRight="#dimen/login_activity_horizontal_margin"
android:layout_marginTop="#dimen/login_activity_vertical_margin"
android:padding="#dimen/login_activity_horizontal_margin"
android:id="#+id/linearLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_marginBottom="#dimen/login_activity_vertical_margin"
android:weightSum="1">
<ImageView
android:layout_width="#dimen/login_activity_logo"
android:layout_height="#dimen/login_activity_logo"
android:id="#+id/imageView"
android:src="#drawable/logo"
android:contentDescription="Icon GG"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/files"
android:id="#+id/textView"
android:textSize="#dimen/login_activity_text"
android:textColor="#android:color/black"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView"
android:layout_marginLeft="10dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/relativeLayout"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="#string/sign_string"
android:textSize="#dimen/login_activity_vertical_margin"
android:textStyle="bold"
android:background="#686868"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:gravity="center"
android:id="#+id/textView3" />
<ImageView
android:id="#+id/sign_thumb"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_alignParentEnd="false"
android:visibility="gone" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eliminar"
android:id="#+id/deleteButton"
android:background="#cc6b67"
android:textStyle="bold"
android:layout_alignBottom="#+id/textView3"
android:layout_alignParentStart="true"
android:visibility="gone" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="#+id/relativeLayout2"
android:layout_marginTop="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#android:color/white"
android:text="#string/images"
android:textSize="#dimen/login_activity_vertical_margin"
android:textStyle="bold"
android:background="#686868"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:gravity="center"
android:id="#+id/textView2" />
<GridView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/gridImages"
android:numColumns="2"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp"
android:layout_alignParentLeft="false"
android:layout_marginLeft="0dp"
android:layout_below="#+id/textView2" />
</RelativeLayout>
</LinearLayout>
<ImageView
android:layout_width="#dimen/login_activity_logo_h"
android:layout_height="#dimen/login_activity_logo_v"
android:id="#+id/imageView2"
android:src="#drawable/logo"
android:layout_below="#+id/linearLayout"
android:layout_alignRight="#+id/linearLayout"
android:layout_marginTop="#dimen/login_activity_vertical_margin"
android:layout_marginBottom="#dimen/login_activity_vertical_margin"
android:contentDescription="#string/logo" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
Here is some simplified example to achieve needed layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_icon" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/sign_thumb"
android:layout_width="match_parent"
android:layout_height="100dp"
android:src="#drawable/ic_icon" />
<Button
android:id="#+id/deleteButton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<GridView
android:id="#+id/gridImages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="2" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_icon" />
</LinearLayout>