Using GridView and LinearLayout , Gridview is expressed in the top on display - java

I am designing layout as follows.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<ScrollView
<LinearLayout
<LinearLayout
<TextViewなど
.
.
.
</LinearLayout>
<LinearLayout
<packagename.ExpandableHeightGridView
</LinearLayout>
</LinearLayout>
</ScrollView>
I was executing the program on the nexus5.
It is as follows, Gridview is expressed in the top on display.
enter image description here
If I scroll to the top, then LinearLayout is expressed.
enter image description here
I tried to adjust the layout.
But GridView wasn't adjusted.
I want to set LinearLayout to the top at first.
public class Activity_CommunicationSpace_MemberList extends Activity {
private List<Data_User> objects = new ArrayList<Data_User>();
private Data_User item = new Data_User();
private String user_name;
private Bitmap user_icon;
private Bitmap user_profile;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_communicationspace_memberlist);
user_name = "Test_Test";
user_icon = BitmapFactory.decodeResource(getResources(), R.drawable.icon_lamborghini);
for (int i = 0; i < 60; i++) {
item = new Data_User();
item.setNameData(user_name);
item.setIconData(user_icon);
objects.add(item);
}
Adapter_CommunicationSpace_MemberList adapter = new Adapter_CommunicationSpace_MemberList(getApplicationContext(), R.layout.adapter_communicationspace_memberlist, objects);
ExpandableHeightGridView expandableHeightGridView = (ExpandableHeightGridView) findViewById(R.id.gridview_communicationspace_memberlist);
expandableHeightGridView.setExpanded(true);
expandableHeightGridView.setAdapter(adapter);
final ScrollView scrollView = (ScrollView) findViewById(R.id.activity_communicationspace_memberlist_scrollView);
scrollView.post(new Runnable() {
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_UP);
}
});
}

If Listview And Gridview Are in Bottom Then its Scroll itself. they Does'nt need Scrollview or ExpendeableGridview in This Case
U Should Try This Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Country Codes"
android:textSize="20sp" />
<Button
android:id="#+id/findSelected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get Selected Items" />
<GridView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"/></LinearLayout>

Related

How to put programmatically created Horizontally Scrolling view with XML created Layout in Android?

In my app a user can select multiple images from gallery then he can view it within the app.
I have three buttons within a Relative Layout
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.codenemesis.multipleimg.MainActivity">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="imageSelector"
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="up"
android:text="Upload"/>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="viewclick"
android:text="View Images" />
To show the images I programmatically created ImageView array within HorizontalScrollView set to WRAP_CONTENT but the problem is when I click on view button HorizontalScrollView span over the whole screen like this.
I want to show HorizontalScrollView below view button. How can I do it?
Here is how I created HorizontalScrollView
HorizontalScrollView horizontalScrollView = new HorizontalScrollView(this);
LinearLayout linearLayout = new LinearLayout(this);
ViewGroup.LayoutParams prams = new ViewGroup.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
linearLayout.setLayoutParams(prams);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
horizontalScrollView.addView(linearLayout);
// mArrayUri is the arraylist of images selected from gallery
int b = mArrayUri.size();
int c = 0;
ImageView[] imageViews = new ImageView[mArrayUri.size()];
while (c < mArrayUri.size()) {
imageViews[c] = new ImageView(this);
imageViews[c].setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
imageViews[c].setPadding(10,0,10,0);
imageViews[c].setImageURI(mArrayUri.get(c));
linearLayout.addView(imageViews[c]);
c++;
// Set context view
setContentView(horizontalScrollView);
The code in your xml file should be like this
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.myapplication.MainActivity">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="select images"
android:onClick="imageSelector"/>
<Button
android:id="#+id/button2"
android:layout_toRightOf="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="up"
android:text="Upload"/>
<Button
android:id="#+id/button3"
android:layout_toRightOf="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="viewclick"
android:text="View Images" />
<RelativeLayout
android:id="#+id/parent_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/button"
android:layout_marginTop="10dp"
>
</RelativeLayout>
The code in you java file should be like this
public class MainActivity extends AppCompatActivity {
RelativeLayout relativeLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
relativeLayout=findViewById(R.id.parent_panel);
}
public void imageSelector(View view)
{
}
public void up(View view)
{
}
public void viewclick(View view)
{
HorizontalScrollView horizontalScrollView =
new HorizontalScrollView(this);
LinearLayout linearLayout = new LinearLayout(this);
ViewGroup.LayoutParams prams = new ViewGroup.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
linearLayout.setLayoutParams(prams);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
horizontalScrollView.addView(linearLayout);
// mArrayUri is the arraylist of images selected from gallery
int b = mArrayUri.size();
int c = 0;
ImageView[] imageViews = new ImageView[mArrayUri.size()];
while (c < mArrayUri.size()) {
imageViews[c] = new ImageView(this);
imageViews[c].setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
imageViews[c].setPadding(10, 0, 10, 0);
imageViews[c].setImageURI(mArrayUri.get(c));
linearLayout.addView(imageViews[c]);
c++;
}
relativeLayout.addView(horizontalScrollView);
}
}
This should do the trick for you.

Can't reach TextView parameters while inflating tableRow

I'm new to Android developing.
At the moment I'm trying to fill in a TableLayout with my data.
The Data part works just well but TextView parameters from TableRow don't affect my design.
Here's my Activity whith the table:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<include layout = "#layout/table_row"/>
</TableLayout>
</ScrollView>
and here's TableRow XML I use to inflate
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FBFBFB">
<TextView
android:id="#+id/number"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="2dp"
android:layout_weight="0"
android:textSize="16sp"/>
<TextView
android:id="#+id/school_name"
android:textSize="16sp"
android:background="#color/colorAccent"
android:layout_weight="1"
android:text="School Name"/>
<TextView
android:id="#+id/rating"
android:textSize="16sp"
android:padding="2dp"
android:layout_weight="2"
android:text="Rating"/>
</TableRow>
and Java code:
public void fillTable () {
TableLayout tableLayout = (TableLayout) findViewById(R.id.table);
LayoutInflater inflater = LayoutInflater.from(this);
for(int i = 0; i<schools.size(); i++){
addRow(i, inflater, tableLayout);
}
}
public void addRow(int num, LayoutInflater inflater, TableLayout parent) {
TableRow tr = (TableRow) inflater.inflate(R.layout.table_row,parent,false);
tr.setId(num + 1);
TextView tv = tr.findViewById(R.id.number);
tv.setText(String.valueOf(num+1));
tv = tr.findViewById(R.id.school_name);
tv.setText(schools.get(num).schoolName);
tv = tr.findViewById(R.id.rating);
tv.setText(String.valueOf(schools.get(num).score));;
final int index = num ;
tr.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, SchoolCard.class);
intent.putExtra(SCHOOL_LINK,schools.get(index).schoolCardLink);
startActivity(intent);
}
});
parent.addView(tr);
}
Can't find where problem is.
Place the TableRow inside the Table tab and run.

Make RelativeLayout scrollable

I want to make a scrollable RelativeLayout where I can create Buttons with a x and y positions and custom width and height.
Here is the code i got so far XML:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/buttonDel"
android:fillViewport="true">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/RL">
</RelativeLayout>
</LinearLayout>
</ScrollView>
Java:
RelativeLayout linearLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
linearLayout = (RelativeLayout) findViewById(R.id.RL);
addButton();
}
private void addButton() {
for(int i = 0; i < 20; i++)
for(int j = 0; j < 4; j++)
{
Button but = new Button(this);
but.setX(j * 200);
but.setY(i * 200);
but.setText("B" + i);
linearLayout.addView(but, 200, 200);
}
}
It result in something that i want except the scrolling part. I don't know why the ScrollView isn't working.
Screen so far.
After I changed ScrollView layout_height="match_parent" to "warp_content"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</RelativeLayout>
</ScrollView>
However the right way to build the requisite structure is to design a gridview or listview .
Use single child for scroll view to behave correctly.
Change the ScrollView height from "match_parent" to "wrap_content" this should fix the problem:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/buttonDel"
android:fillViewport="true"
>
...

ScrollView Android with images

I want to put three images on a vertical scroll view, I don't know why, but I just see the third one ( tuto3 ).
here is the xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView" >
<LinearLayout
android:id="#+id/linearLayout42"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</LinearLayout>
</ScrollView>
</LinearLayout>
And there the class:
public class about extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aboutlayout);
LinearLayout ll = (LinearLayout) findViewById(R.id.linearLayout42);
ImageView image = new ImageView(about.this);
image.setBackgroundResource(R.drawable.tuto1);
ll.addView(image);
ImageView image2 = new ImageView(about.this);
image.setBackgroundResource(R.drawable.tuto2);
ll.addView(image2);
ImageView image3 = new ImageView(about.this);
image.setBackgroundResource(R.drawable.tuto3);
ll.addView(image3);
}
}
You keep calling setBackgroundResource on image instead of image, image1, and image2.

Slide Down Android (no animation)

Hi I need some help in understand this property/functionality from Android...
Maybe I can looking around for something wrong... but I'm almost sure that I need use the slide down "property" to see the rest of my textview... rigth?
But how? I am not understanding the flow...
public class PrintBtInvoice extends Activity
{
String constActivityName = "PrintBtInvoice";
// ------------------------------------------------------------------------
ScrollView sView = null;
TextView txtIDorder = null;
TextView txt2Print = null;
TextView txt2View = null;
Button btnBack = null;
Button btnPrint = null;
public void onCreate(Bundle savedInstanceState)
{
sView = (ScrollView) findViewById(R.id.scrollView );
txtIDorder = (TextView) findViewById(R.id.txtPBIorderId);
txt2Print = (TextView) findViewById(R.id.txtPBIinvoice2print);
txt2View = (TextView) findViewById(R.id.txtPBIinvoice2view);
btnBack = (Button) findViewById(R.id.btnPBIback);
btnPrint = (Button) findViewById(R.id.btnPBIprint);
...
}
btnPrint.setOnClickListener(new OnClickListener()
{ ... }
}
What I need to do to see the rest of my text2Print??
Changes suggested :)
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scrollView"
android:layout_gravity="center_horizontal" >
<TextView
android:id="#+id/txtPBIinvoice2print"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/btnPBIback"
android:layout_toLeftOf="#+id/btnPBIprint"
android:text="#string/app_blank" />
</ScrollView>
I think you need to put your TextView into ScrollView. This way you would be able to scroll your text down and see it. Here is the sample XML layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scrollView"
android:layout_gravity="center_horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView" />
</ScrollView>
</LinearLayout>

Categories