How Create more TextView in RelativeLayout in rows android - android

how to create more TextView in relativelayout like
my code not showing
not like that :
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(5, 10, 5, 10);
params.setMarginStart(40);
params.setMarginEnd(40);
for (int a = 0; a < alquran.getindokata().length; a++) {
textView = new TextView(context);
textView.setLayoutParams(params);
textView.setId(a);
textView.setGravity(Gravity.CENTER);
textView.setPadding(10, 5, 10, 5);
textView.setBackgroundColor(context.getResources().getColor(R.color.hitam_pudar));
textView.setText(alquran.getarabkata()[a] + "\n" + alquran.getindokata()[a]);
Log.d(TAG, "VerseID " + id_surat +
" getKata " + alquran.getindokata()[a]
);
holder.terjemahankata.addView(textView);
}

From the image you supplied, I suggest you a non-official Google library FlexBoxLayout for this. You got variety of options to choose from:
flexDirection
flexWrap
justifyContent
alignItems
alignContent
and many more!
You can dynamically add elements (TextView, in your case), in FlexBoxLayout, and it will get arranged as you need.

To add more textview to single layout you can use library “FlexboxLayout”.
Following is the code to implement this library to your project:
Add this to your build.gradle file
compile 'com.google.android:flexbox:0.2.6'
Add this to main layout file
<com.google.android.flexbox.FlexboxLayout
android:id="#+id/flexBoxLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:alignContent="flex_start"
app:alignItems="flex_start"
app:flexDirection="row"
app:flexWrap="wrap"
app:justifyContent="flex_start" />
Another textview file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/tvTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Test"
android:background="#drawable/rounded_corner_green"
android:padding="10dp"
android:textColor="#android:color/white"
android:textStyle="bold"
android:textSize="12sp" />
</LinearLayout>
Java Code
public class MainActivity extends AppCompatActivity {
private FlexboxLayout flexBoxLayout;
private List<String> List = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.flex_activity);
flexBoxLayout = (FlexboxLayout) findViewById(R.id.flexBoxLayout);
List.add("Test Content");
List.add("Content");
List.add("Test Content");
List.add("Test");
List.add("Test Content");
List.add("Content");
List.add("Test Content");
List.add("Test");
setView();
}
public void setView() {
flexBoxLayout.removeAllViews();
for (int i = 0; i < List.size(); i++) {
final int pos = i;
final View tagView = this.getLayoutInflater().inflate(R.layout.item_select_intrest_tag, null);
final TextView tvTag = (TextView) tagView.findViewById(R.id.tvTag);
tvTag.setText(List.get(i));
tvTag.measure(0, 0);
tvTag.getMeasuredWidth();
tvTag.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "Test Clicked", Toast.LENGTH_SHORT).show();
}
});
flexBoxLayout.addView(tagView);
}
}
}

Related

How to add two views next to each other in LinearLayout programatically?

I have seen some explanations on how to add two views next to each other in LinearLayout by using XML. How can this be done programatically?
I have the following two methods:
private void createListOfInstalledApplications() {
installedApplicationNames = this.getApplicationNames();
installedPackages = this.getPackageNames();
for(int i = 0; i < installedApplicationNames.size(); i++){
TextView scrollAppsView = new TextView(this);
scrollAppsView.setId(i);
scrollAppsView.setText(installedApplicationNames.get(i) + "\n ");
layout.addView(scrollAppsView);
}
}
This method adds the names of installed applications on the Android phone to the LinearLayout. On the right side of these applications, I would like to have a drop down menu where some settings can be chosen. For now the following methods adds the Spinners to the LinearLayout:
private void createDropDownMenuesForApplications() {
List<String> vibPatternNames = new ArrayList<String>();
VibrationPatternManager vibPatManager = VibrationPatternManager.getInstance();
List<VibrationPattern> vibrationPatterns = vibPatManager.getAllAvailablePatterns();
for(VibrationPattern vibrationPattern : vibrationPatterns){
vibPatternNames.add(vibrationPattern.getName());
}
for(int i = 0; i < installedApplicationNames.size(); i++){
Spinner dropDownMenu = new Spinner(this);
dropDownMenu.setId(i);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, vibPatternNames);
dropDownMenu.setAdapter(dataAdapter);
layout.addView(dropDownMenu);
}
}
The drop-down menus now appear below the application names. However, I would like them to appear to the right. So
"ApplicationName1 drop-down-menu1"
instead of
ApplicationName1
ApplicationName2
Drop-down-menu1
Drop-down-menu2
How do I do this?
Just do
layout.setOrientation(Horizontal)
I have done similar task as required by you, please have a look at my answer:
https://stackoverflow.com/a/33339420/5479863
in JSON response image URLs were provided so, at runtime I have to add views dynamically adjacent to each other.
Look at the answer to know more...
I hope that will help you...
Happy coding :)
Try the following:
1) MActivity.class--------------
public class MActivity extends AppCompatActivity {
private LinearLayout layout_horizontal;
private LinearLayout layout_vertical;
private LayoutInflater layoutInflater;
private FrameLayout fl;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
// Frame layout generic container --- root.
// Frame layout has as a direct child layout_vertical (Linear layout with orientation vertical).
// for each item inside installedApplicationNames, re-create a linear layout with orientation horizontal (layout_horizontal),
// with a TextView and Spinner and then add it as a direct child of the linear layout with orientation vertical.
fl = (FrameLayout) findViewById(R.id.fl);
layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.layout_vertical , null);
fl.addView(view);
layout_vertical = (LinearLayout) view.findViewById(R.id.ll_v);
populate();
}
private void populate() {
layout_vertical.removeAllViews();
List<String> installedApplicationNames = new ArrayList<String>();
for (int k = 0; k < 30; k++) {
installedApplicationNames.add("N" + k);
}
for (int i = 0; i < installedApplicationNames.size(); i++) {
View view1 = layoutInflater.inflate(R.layout.layout_horizontal , null);
layout_horizontal = (LinearLayout) view1.findViewById(R.id.ll_h);
TextView scrollAppsView = new TextView(this);
scrollAppsView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT , ViewGroup.LayoutParams.WRAP_CONTENT));
scrollAppsView.setId(i);
scrollAppsView.setText(installedApplicationNames.get(i) + "\n ");
layout_horizontal.addView(scrollAppsView);
// TODO: use a certain method to get vibPatternNames for the current installedApplicationName
List<String> vibPatternNames = new ArrayList<String>();
for (int j = 0; j < 4; j++) {
vibPatternNames.add("S" + j);
}
Spinner dropDownMenu = new Spinner(this);
dropDownMenu.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
dropDownMenu.setId(i);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, vibPatternNames);
dropDownMenu.setAdapter(dataAdapter);
layout_horizontal.addView(dropDownMenu);
layout_vertical.addView(layout_horizontal);
}
}
}
2) layout.xml-----------
<?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:fillViewport="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginTop="5dp"
android:id="#+id/fl">
</FrameLayout>
</ScrollView>
3) layout_vertical.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:id="#+id/ll_v"
android:layout_gravity="center"
android:orientation="vertical">
</LinearLayout>
4) layout_horizontal.xml---------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/ll_h"
android:layout_gravity="center"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>

Dynamically add TableRow to above of TableLayout

I want to dynamically add TableRow to above of TableLayout. I use blow code:
In my activity:
TableLayout table = (TableLayout)ChatActivity.this.findViewById(R.id.tblChats);
for(int i = 1; i < 10; ++i)
{
TableRow row = (TableRow)LayoutInflater.from(ChatActivity.this).inflate(R.layout.chat_row, null);
((TextView)row.findViewById(R.id.attrib_name)).setText("A");
((TextView)row.findViewById(R.id.attrib_value)).setText(i + "");
table.addView(row);
}
table.requestLayout();
chat_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="#+id/attrib_name"
android:textStyle="bold"/>
<TextView android:id="#+id/attrib_value"
android:gravity="right"
android:textStyle="normal"/>
</TableRow>
As you know these codes adds TableRow in the bottom of the TableLayout.
Is there any way to add it to the above of TableLayout?
yes you can add row as runtime in table layout.
use below code like chart.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tblChats"
android:layout_width="match_parent"
android:layout_height="match_parent"> </TableLayout>
and make activity like below ..
public class ChartActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chart_layout);
TableLayout table = findViewById(R.id.tblChats);
for (int i = 0; i < 5; i++) {
TableRow row = new TableRow(this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
row.setLayoutParams(lp);
TextView textView = new TextView(this);
textView.setText("Name" + " " + i);
EditText editText = new EditText(this);
row.addView(textView);
table.addView(row, i);
}
}
}
According to Android Team's answer I realized I must change this line:
table.addView(row);
to this:
table.addView(row, 0);

Trying to set up views under each other programatically in a fragment

In my fragment's onCreateView method I'm trying to programatically inflate viewstubs to layouts under each other, but the first two takes place inside each other, like this
Here is my fragment's onCreateView method
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mBaseLayout = (PercentRelativeLayout) inflater.inflate(R.layout.fragment_calender, container, false);
findViews();
mBundle = new Bundle();
mFragments = new ArrayList<>();
mDaysContainer = (RelativeLayout) mBaseLayout.findViewById(R.id.daysContainer);
mStartPeriod = DateAndTime.getFirstDayFirstWeekOfMonthAsString("yyyy-MM-dd");
mEndPeriod = DateAndTime.getLastDayLastWeekOfMonthAsString("yyyy-MM-dd");
mPeriodTextView.setText(mStartPeriod + " - " + mEndPeriod);
createDayFragments(); // Create the fragments
findDayViewIds(); // Get access to the views
return mBaseLayout;
}
I use this method to create the views and put them into the container
private void createDayFragments() {
for (int i = 0; i < 30; i++) {
mFragments.add(new ViewStub(getActivity()));
mFragments.get(i).setId(i);
mDaysContainer.addView(mFragments.get(i));
ViewStub viewStub = (ViewStub) mBaseLayout.findViewById(i);
viewStub.setInflatedId(i);
viewStub.setLayoutResource(R.layout.fragment_day);
Log.d("ID", mFragments.get(i).getId() + "");
Log.d("i = ", i + "");
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if(i >= 1){
p.addRule(RelativeLayout.BELOW, i - 1);
Log.d("Below ID", i - 1 + "");
}
viewStub.setLayoutParams(p);
Log.d("", "");
viewStub.inflate();
}
}
And I use this method to get access to all the views after creating them
private void findDayViewIds(){
for(int i = 0; i < 30; i++) {
RelativeLayout tmpRel = (RelativeLayout) mDaysContainer.findViewById(i);
for(int j = 0; j < tmpRel.getChildCount(); ++j){
if(tmpRel.getChildAt(j) instanceof PercentRelativeLayout) {
PercentRelativeLayout percentTmp = (PercentRelativeLayout) tmpRel.getChildAt(j);
percentTmp.setId(100 + i);
for(int h = 0; h < percentTmp.getChildCount(); ++h){
if(percentTmp.getChildAt(h) instanceof TextView){
TextView textViewTmp = (TextView) percentTmp.getChildAt(h);
textViewTmp.setId(300 + i);
textViewTmp.setText("Day " + i + " ID: " + tmpRel.getId());
}
}
} else if (tmpRel.getChildAt(j) instanceof ViewStub){
tmpRel.getChildAt(j).setId(200 + i);
}
}
}
}
Here is the XML for the fragment that should contain the other fragments
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/weekDisplayed">
<TextView
android:text="Placeholder"
android:layout_alignParentTop="true"
android:gravity="center"
app:layout_heightPercent="10%"
app:layout_widthPercent="94%"
android:layout_centerHorizontal="true"
android:background="#drawable/datefrom_dateto_bottom_border"
android:id="#+id/periodTextView"/>
<ScrollView
android:id="#+id/scrollView"
app:layout_widthPercent="94%"
android:layout_below="#+id/periodTextView"
android:layout_centerHorizontal="true"
app:layout_marginBottomPercent="4%"
android:layout_width="match_parent">
<RelativeLayout <!-- This is where i want the fragments -->
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/daysContainer">
</RelativeLayout>
</ScrollView>
</android.support.percent.PercentRelativeLayout>
And here is the xml for the fragment I want to inflate into my daysContainer relative layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<android.support.percent.PercentRelativeLayout
android:gravity="center_vertical"
android:id="#+id/dayContainerOne"
android:layout_width="match_parent"
android:layout_height="35dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
app:layout_marginLeftPercent="2%"
android:text="placeholder"
android:id="#+id/weekOneTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:typeface="monospace"/>
</android.support.percent.PercentRelativeLayout>
<ViewStub layout="#layout/fragment_replace"
android:id="#+id/replaceOne"
android:layout_below="#id/dayContainerOne"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</ViewStub>
</RelativeLayout>
Try shifting ids up by 1. So your first id is not equal to 0. My guess is that BELOW doesn't work if given id equals 0.
Update to my comment.
Found the following line in RelativeLayout sources:
rules[BELOW] = a.getResourceId(attr, 0);
Where 0 is the default value, therefore it is ignored.

Create buttons programmatically goes new line

I created a layout which programmatically created buttons (see code). With this layout I have a column of buttons, but I would create something like the picture below. I tried something with linear layout but the buttons didn't go to new line automatically and didn't show, so I change it to table layout. How can I create something like the picture programmatically?
Thank you.
protected TableLayout layout;
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layout = (TableLayout) findViewById(R.id.workflows_activity_layout);
private void createButton() {
loading.setVisibility(View.VISIBLE);
layout.removeAllViews();
if (items.length == 0) {
TableRow row = new TableRow(this);
TextView no_item = new TextView(this);
no_questions.setText("there are no items");
no_questions.setTextSize(35);
row.addView(no_item);
layout.addView(row);
} else {
for (int i = 0; i < items.length; i++) {
TableRow row = new TableRow(this);
final Button btn = new Button(this);
TextView tw = new TextView(this);
tw.setText(items[i].getName());
tw.setTextSize(25);
btn.setBackgroundResource(R.drawable.button_image);
btn.setId(i);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int btn_selected = btn.getId();
Intent openItempage = new Intent(MainActivity.this, ItemsActivity.class);
startActivity(openItempage);
}
});
row.addView(btn);
row.addView(tw);
layout.addView(row, params);
items_buttons.add(btn);
items_nameText.add(tw);
}
}
loading.setVisibility(View.GONE);
}
There's an easy way to achieve what you want. Look at this code:
<?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:layout_gravity="center_horizontal"
android:orientation="vertical">
<TableLayout
android:id="#+id/tab_lay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:stretchColumns="*"
android:gravity="center_vertical" />
TabLayout tab_lay = (TableLayout)view.findViewById(R.id.tab_lay);
for(int i = 1; i <= 4; ){
TableRow a = new TableRow(getActivity());
TableRow.LayoutParams param = new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT, 1.0f);
a.setLayoutParams(param);
a.setGravity(Gravity.CENTER_VERTICAL);
for(int y = 0; (y < 2) && (i <= 4); y++) {
Button x = new Button(getActivity());
x.setText("Text " + i);
x.setGravity(Gravity.CENTER);
TableRow.LayoutParams par = new TableRow.LayoutParams(y);
x.setLayoutParams(par);
int ids = i;
x.setId(ids);
x.setOnClickListener(this);
a.addView(x);
i++;
}
tab_lay.addView(a);
}
If you want more buttons, then just change 4 which is compare to i to your value. Hope I help.
You can implement this using labraries, for instance
FlowLayout
Usage:
<com.wefika.flowlayout.FlowLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="start|top">
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lorem ipsum" />
</com.wefika.flowlayout.FlowLayout>
Another solution is:
AndroidFlowLayout
Usage:
<com.liangfeizc.flowlayout.FlowLayout
android:id="#+id/flow_layout"
flowlayout:vertical_spacing="10dp"
flowlayout:horizontal_spacing="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

How to manage linear sub layout programmatically?

Issue about layout aliment.
i want to add view dynamically.
Logical code :
linear1 = (LinearLayout) findViewById(R.id.parent);
linear2 = (LinearLayout) findViewById(R.id.chiled);
int len = 4;
for (int i = 1; i <= len; i++) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
params1.gravity = Gravity.RIGHT;
final int id_txt;
ImageView iv = new ImageView(this);
iv.setId(i);
id_txt = iv.getId();
iv.setBackgroundResource(R.drawable.ic_launcher);
linear1.addView(iv, params);
iv = ((ImageView) findViewById(id_txt));
for (int j = 1; j < 2; j++) {
final int id_;
Button btn = new Button(this);
btn.setId(i);
id_ = btn.getId();
btn.setText("button " + id_);
linear2.addView(btn, params1);
btn = ((Button) findViewById(id_));
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(v.getContext(),
"Button clicked index = " + id_,
Toast.LENGTH_SHORT).show();
}
});
}
// btn.setBackgroundColor(Color.rgb(70, 80, 90));
// linear1.addView(txt, params);
// params.addRule(RelativeLayout.RIGHT_OF, txt.getId());
iv.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Toast.makeText(view.getContext(),
"text clicked index = " + id_txt,
Toast.LENGTH_SHORT).show();
}
});
}
}
Xml Code :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/chiled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
I want to add image in parent view and two button in child view dynamical.
I inspires to make this type view form
Android heterogeneous gridview like pinterest?
It should be like as
current output as
I don't know where is the problem.
One strange issues i am facing now in my editor if i see layout in code then its shows me android:orientation="vertical" and if i see in outline that shows android:orientation="horizontal" for each layout. how is it possible ?
Help me to solve out.Thanks
EDIT:
First off, start by adding your buttons to the xml. Along with the image view.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/extra_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/chiled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Like" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dislike" />
</LinearLayout>
</LinearLayout>
You can then remove any concept of adding views, as they already exist.
package com.example.yul;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class extra extends Activity {
Button like, dislike;
LinearLayout root, sub;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.extra);
like = (Button) findViewById(R.id.button1);
dislike = (Button) findViewById(R.id.button2);
// add button listeners here.
ImageView iv = (ImageView) findViewById(R.id.image);
iv.setBackgroundResource(R.drawable.ic_launcher);
}
}
}
This will only display the one image though, with buttons.
What you need to do is apply this xml, and code to a gridView or similar. As you will have id clashes otherwise.
Since the horizontal LinearLayout chiled is the first child of the vertical LinearLayout parent it is aligned as the first item. So adding Views to it will place them on top.
Try moving the chiled Layout to the root LinearLayout root.

Categories

Resources