How come my LinearLayout with dynamically added images won't take parameters ?
LinearLayout ImageView = (LinearLayout) findViewById(R.id.settings);
LinearLayout ImageView2 = (LinearLayout) findViewById(R.id.settings2);
LinearLayout.LayoutParams imagev = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
imagev.topMargin=2;
ImageView image = new ImageView(getApplicationContext());
image.setBackgroundResource(R.drawable.ic_action_discard);
image.setId(Integer.parseInt(listitems.get(n).get("cbid")));
image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(final View v) {
showpopup(v.getId());
}
});
if (listitems.get(n).get("state").toString().equals("1")) {
cb.setChecked(true);
my_checked_layout.addView(cb,params);
cb.setBackgroundColor(Color.argb(255, 184, 239, 220));
cb.setTextColor(Color.rgb(255, 255, 255));
ImageView2.addView(image, imagev);
} else {
cb.setChecked(false);
cb.setBackgroundColor(Color.argb(255, 19, 202, 140));
cb.setTextColor(Color.rgb(255, 255, 255));
my_layout.addView(cb,params);
ImageView.addView(image,imagev);
}
The my_checked_layout(cb, params); does take the other params
my XML, where the images and checkboxes are being set.
the parts that are being used are in both linear layouts with the id's Parent & parent2.
<?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" >
<!-- Name Label -->
<LinearLayout
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/name_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dip"
android:paddingTop="10dip"
android:textColor="#43bd00"
android:textSize="25dip"
android:textStyle="bold" />
<!-- green -->
<!-- Email Label -->
<TextView
android:id="#+id/email_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#EB0505" />
<!-- red -->
<TextView
android:id="#+id/list_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FF00FF" />
<!-- pink -->
<LinearLayout
android:id="#+id/Parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/test"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp" />
<LinearLayout
android:id="#+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#13ca8c"
/>
</LinearLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="2dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp"
android:scaleType="fitXY"
android:src="#drawable/devider" />
<LinearLayout
android:id="#+id/Parent2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/checked"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
/>
<LinearLayout
android:id="#+id/settings2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#B8EFDC" />
</LinearLayout>
</LinearLayout>
</ScrollView>
If you want to add margin within the LinearLayout.LayoutParams you can call the setMargin() method of it.
example:
setMargins(135, 176, 0, 0);
where setMargins (int left, int top, int right, int bottom)
<LinearLayout
android:id="#+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
/>
fixed it.
Related
I have one relativeLayout and three view's inside RelativeLayout. There views are place on each other.
<RelativeLayout
android:id="#+id/includelayoutgroup"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/transparentColorView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:visibility="visible" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<include
layout="#layout/transfer_keyboard_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/finalRequestView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:visibility="visible">
<include
layout="#layout/fragment_transfer_new_version_container_child"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</RelativeLayout>
Is it a possible to reverse position my view's? I mean,in my code last Layout is finalRequestView and in button click i would to my last view in first position,and other view's place on my view,
How i can solve this problem?
I try to reverse layout by following demo & it works as you want, please take a look
ReverseLayout.java
public class ReverseLayout extends AppCompatActivity {
LinearLayout llRoot;
Button btReverseLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reverse_layout);
llRoot = (LinearLayout) findViewById(R.id.llRoot);
btReverseLayout = (Button) findViewById(R.id.btReverseLayout);
btReverseLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ArrayList<View> alViews = new ArrayList<View>();
for (int i = llRoot.getChildCount() - 1; i >= 0; i--) {
View view = llRoot.getChildAt(i);
llRoot.removeViewAt(i);
alViews.add(view);
}
for (int j = 0; j < alViews.size(); j++) {
llRoot.addView(alViews.get(j));
}
}
});
}
}
reverse_layout.xml layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_6"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.tosc185.testproject.Activity6">
<LinearLayout
android:id="#+id/llRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00FF00"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000FF"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/btReverseLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Reverse Layout" />
</RelativeLayout>
I'm fairly new to android and xml layouting. I've been trying to make an app, and already done with the programming bit. However i'm stuck on the finalisation of the layout. Really need a hand. My app should look like this:
I've divided the screen in 4 Linear Layouts as I have numbered in the picture as seen below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.FirstVersion.android.cwd.Play"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#color/material_blue_grey_800">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnGoBack"
android:text="Go Back"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profile Information"
android:background="#color/accent_material_dark"
android:layout_weight="10" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/LDrawerAction"
android:text="Menu"
android:clickable="false"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp" />
</LinearLayout>
//endregion
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Section2"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Section3"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="5sp"
android:textColor="#color/colorWhite"
android:background="#990000"
android:maxLines = "3"
android:scrollbars = "vertical"
android:id="#+id/txtSection3" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="15"
android:orientation="vertical"
android:baselineAligned="false">
<TableLayout
android:id="#+id/Section4"
android:layout_width="match_parent"
android:layout_weight="15"
android:layout_height="wrap_content">
</TableLayout>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
The problem now is that, the second section is filled programmatically and it has a range of rows from 8 to 14. The same for the columns. Every block is a different button which I add with this code:
Lay= (LinearLayout)findViewById(R.id.Section2);
for (int row = 0; row < numberOfRows; row++)
{
LinearLayout Linearrow = new LinearLayout(this);
Linearrow.setOrientation(LinearLayout.HORIZONTAL);
for (int column = 0; column < numberOfColumns; column++)
{
View a = Chosen.blocks[row][column]; //This is a View the extend Button that has no layout properties defined
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 1.0f);
a.setLayoutParams(params);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
lp.weight = 1.0f;
Linearrow.addView(a, lp);
}
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
lp.weight = 1.0f;
Lay.addView(Linearrow, lp);
}
I have tried even using a TableLayout and assigning a small image as background so it could get resized with the following code:
TL =(TableLayout)fa.findViewById(R.id.Section2);
for (int i = 0; i < numberOfRows; i++)
{
TableRow tableRow = new TableRow(c);
for(int j = 0; j < numberOfColumns; j++)
{
String s = T[(i * 10) + j];
Block b = new Block(c, s);
//int w = Math.round(c.getResources().getDisplayMetrics().density * 20);
//int h = Math.round(c.getResources().getDisplayMetrics().density * 80);
//b.setLayoutParams(new TableRow.LayoutParams(w, h, 2.0f));
b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
b.setBackgroundResource(R.drawable.g_3);
tableRow.addView(b);
tableRow.setLayoutParams(new android.widget.LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 5f));
final Block fb = b;
}
TL.addView(tableRow);
}
When I run the app, I can see that unless I open it on a big screen phone, the content is not visible entirely(as if the height is set fixed manually of the layouts), and since it is not scroll-able, the content is not visible. How can I rearrange or modify the layout so it looks as in the picture above?
Make fixed height of layouts using layout_weight
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:weightSum="12"
android:orientation="horizontal"
android:background="#color/material_blue_grey_800">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnGoBack"
android:text="Go Back"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profile Information"
android:background="#color/accent_material_dark"
android:layout_weight="10" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/LDrawerAction"
android:text="Menu"
android:clickable="false"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:weightSum="1"
android:id="#+id/Section2"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:id="#+id/Section3"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="5sp"
android:textColor="#android:color/white"
android:background="#990000"
android:maxLines = "3"
android:scrollbars = "vertical"
android:id="#+id/txtSection3" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:weightSum="15"
android:orientation="vertical"
android:baselineAligned="false">
<TableLayout
android:id="#+id/Section4"
android:layout_width="match_parent"
android:layout_weight="15"
android:layout_height="wrap_content">
</TableLayout>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
And in your java class where you add views dynamically, calculate the weights of children accordingly as given below
Lay= (LinearLayout)findViewById(R.id.Section2);
Lay.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int totalWidth = Lay.getMeasuredWidth();
float rowWeight = 1 / numberOfRows;
int columnWidth = totalWidth / numberOfColumns;
for (int row = 0; row < numberOfRows; row++)
{
LinearLayout Linearrow = new LinearLayout(this);
Linearrow.setOrientation(LinearLayout.HORIZONTAL);
for (int column = 0; column < numberOfColumns; column++)
{
View a = Chosen.blocks[row][column]; //This is a View the extend Button that has no layout properties defined
// height is determined by row's layout weight
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(columnWidth,
LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
a.setLayoutParams(params);
Linearrow.addView(a);
}
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
lp.weight = rowWeight;
Lay.addView(Linearrow, lp);
}
I've not tested these, but just might work with few changes that you can figure out once you run this code.
Use
android:layout_weight
attribute to arrange in equal parts in linear layout.
See in the Link
It is better to use View inside ScrollView. Use the below code:-
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.FirstVersion.android.cwd.Play"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#color/material_blue_grey_800">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnGoBack"
android:text="Go Back"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profile Information"
android:background="#color/accent_material_dark"
android:layout_weight="10" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/LDrawerAction"
android:text="Menu"
android:clickable="false"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp" />
</LinearLayout>
//endregion
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Section2"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Section3"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="5sp"
android:textColor="#color/colorWhite"
android:background="#990000"
android:maxLines = "3"
android:scrollbars = "vertical"
android:id="#+id/txtSection3" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="15"
android:orientation="vertical"
android:baselineAligned="false">
<TableLayout
android:id="#+id/Section4"
android:layout_width="match_parent"
android:layout_weight="15"
android:layout_height="wrap_content">
</TableLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
I want to set the scroll view height, width, margin and set at below the text view and at the right of relative layout. I tried to set only height of scroll view dynamically. But how to set margin of scroll view and how to keep it programmatically at:
android:layout_below="#+id/item_textInspectorName"
android:layout_toRightOf="#+id/rel_out_two"
Here is my XML code
<RelativeLayout> ................
<ScrollView
android:id="#+id/scrollExpand"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_below="#+id/item_textInspectorName"
android:layout_toRightOf="#+id/rel_out_two"
android:layout_marginLeft="7.5dp"
android:layout_marginRight="10dp"
android:layout_marginTop="6dp"
android:background="#android:color/white"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.example.tazeen.classnkk.ExpandableTextView
android:id="#+id/expandable_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:ellipsize="end"
android:text="expand"
android:textColor="#android:color/black"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
</ScrollView>
</RelativeLayout> ................
And here is my Activity code which is set the height of dynamically .
ExpandableTextView txtRemark = (ExpandableTextView)findViewById(R.id.expandable_text);
int strRemarkLength = strRemark.length();
if(strRemarkLength > 100)
{
txtRemark.setText(strRemark.concat(" ...Less"));
Log.e("", " Lesss !!!");
scrollView.setLayoutParams(new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT, 350));
}
else
{
txtRemark.setText(strRemark);
Log.e("", "Not Lesss !!!");
}
Here is my sample
MainActivity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorAccent"
android:gravity="center">
<TextView
android:id="#+id/top_textview"
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="Top Text" />
<TextView
android:id="#+id/left_textview"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_below="#+id/top_textview"
android:text="Left Text"/>
<ScrollView
android:id="#+id/scrollExpand"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/expandable_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="expand"
android:textColor="#android:color/black"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
MainActivity.Java
ScrollView scrollView = (ScrollView) findViewById(R.id.scrollExpand);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
params.setMargins(20, 20, 20, 20);
params.addRule(RelativeLayout.BELOW, R.id.top_textview);
params.addRule(RelativeLayout.RIGHT_OF, R.id.left_textview);
scrollView.setLayoutParams(params);
I am building an application in which I want to add multiple images in a horizontal scrollview and want to scroll these imageson click of two (left and right) srcolling buttons, but I am not able to do that as I am new to android development.So can anybody provide my with the solution how to do it ? Thanks in advance....
put this code in your xml
<HorizontalScrollView
android:id="#+id/xml_full_img_hor_below_view"
android:layout_width="match_parent"
android:layout_height="#dimen/full_img_below_relative_height"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/xml_full_img_linear_below_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
/////////////////////////////////////
java code
this model_ProductMaster.listProductImages.size() is images list:
private void setProductImageInView() {
LayoutInflater layoutInflater = (LayoutInflater) viewFullImage
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
linear_below_img_view.removeAllViews();
// Set the image height,widt,scaling and margin of the imageview
for (int i = 0; i < model_ProductMaster.listProductImages.size(); i++) {
convertView = layoutInflater.inflate(
R.layout.xml_row_full_image_view, null, false);
final ImageView img = (ImageView) convertView
.findViewById(R.id.xml_full_img_below_middleimg);
img.setMinimumWidth((int) viewFullImage.getResources()
.getDimension(R.dimen.full_img_below_img_width_height));
img.setMaxWidth((int) viewFullImage.getResources().getDimension(
R.dimen.full_img_below_img_width_height));
img.setMinimumHeight((int) viewFullImage.getResources()
.getDimension(R.dimen.full_img_below_img_width_height));
img.setMaxHeight((int) viewFullImage.getResources().getDimension(
R.dimen.full_img_below_img_width_height));
img.setScaleType(ScaleType.CENTER_INSIDE);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(10, 0, 0, 0);
layoutParams.gravity = Gravity.CENTER;
convertView.setLayoutParams(layoutParams);
img.setScaleType(ScaleType.FIT_XY);
imageLoader.displayImage(
model_ProductMaster.listProductImages.get(i).ImageUrl, img,
options, animateFirstListener);
linear_below_img_view.addView(convertView);
convertView.setId(i);
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
for (int i = 0; i < linear_below_img_view.getChildCount(); i++) {
View view = linear_below_img_view.getChildAt(i);
if (view == v) {
view.setBackgroundResource(R.drawable.xml_popup_border_with_bg);
} else {
view.setBackgroundResource(R.drawable.common_bg_with_dark_border);
}
}
loadImageonCenter(model_ProductMaster.listProductImages
.get(v.getId()).ImageUrl);
System.gc();
}
});
}
linear_below_img_view.getChildAt(0).setBackgroundResource(
R.drawable.xml_popup_border_with_bg);
// Image Starting load
System.gc();
}
main.xml
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="100dp" >
<ImageView
android:id="#+id/xml_home_screen_img_leftarrow"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:padding="5dp"
android:src="#drawable/leftarrow" />
<HorizontalScrollView
android:id="#+id/xml_full_img_hor_below_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/xml_full_img_linear_below_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:orientation="horizontal" >
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="#layout/xml_row_full_image_view" />
<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="#layout/xml_row_full_image_view" />
<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="#layout/xml_row_full_image_view" />
<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="#layout/xml_row_full_image_view" />
<include
android:layout_width="wrap_content"
android:layout_height="match_parent"
layout="#layout/xml_row_full_image_view" />
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:id="#+id/xml_home_screen_img_rightarrow"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:padding="5dp"
android:src="#drawable/rightarrow" />
</RelativeLayout>
xml_row_full_image_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/xml_full_img_below_mainlinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:orientation="horizontal"
android:padding="4dp" >
<ImageView
android:id="#+id/xml_full_img_below_middleimg"
android:layout_width="50dp"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher" />
</LinearLayout>
im creating and application which have thre nodes (Description, Contents, Nutrition) like this image http://imgur.com/TmJT6GI when user click any node it will expend and show another screen inside it how i will do that? i will see there is expendable listview available but its show single list on each node like this example http://ranfeng0610.blog.163.com/blog/static/1857082842011727111359969/ is expend listview in each node i lie to expend layout on reach node al node show difrent layout User interface) how i willl make screenlike this? help me please u have any idea????
1、main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- 禁用系统自带图标android:groupIndicator="#null" -->
<ExpandableListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:groupIndicator="#null"
android:id="#+id/mExpandableListView"
/>
</LinearLayout>
2、group.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation = "horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width = "25dip"
android:layout_height = "25dip"
android:layout_marginTop="10dip"
android:id="#+id/mImageView"
/>
<TextView
android:id = "#+id/group_tv"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:paddingLeft = "30px"
android:paddingBottom = "10px"
android:textSize = "26sp"/>
</LinearLayout>
3、child.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation = "horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_gravity = "center_vertical"
android:id = "#+id/child_iv"
android:layout_width = "70px"
android:layout_height = "70px"
android:paddingLeft = "30px"
android:paddingTop = "2px"
android:paddingBottom = "5px"
android:src = "#drawable/icon"/>
<TextView
android:layout_gravity = "center_vertical"
android:id = "#+id/child_tv"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:paddingLeft = "30px"
android:paddingTop = "10px"
android:paddingBottom = "5px"
android:textSize = "30sp"/>
</LinearLayout>
u can make it without using expandable list-view..u have to just control visibility of your views.
MainActivity
boolean flag;
boolean flag2;
LinearLayout llContains;
LinearLayout llContents;
LinearLayout llContains2;
LinearLayout llContents2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
llContains = (LinearLayout)findViewById(R.id.llContains);
llContents = (LinearLayout)findViewById(R.id.llContents);
llContains2 = (LinearLayout)findViewById(R.id.llContains2);
llContents2 = (LinearLayout)findViewById(R.id.llContents2);
llContains.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
if(!flag)
{
llContents.setVisibility(View.VISIBLE);
flag = true;
}
else
{
llContents.setVisibility(View.GONE);
flag = false;
}
}
});
llContains2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
if(!flag2)
{
llContents2.setVisibility(View.VISIBLE);
flag2 = true;
}
else
{
llContents2.setVisibility(View.GONE);
flag2 = false;
}
}
});
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/llContains"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#000000"
>
</LinearLayout>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Contains"
android:textSize="20dp"
android:layout_marginLeft="10dp"
android:padding="10dp"
/>
<LinearLayout
android:id="#+id/llContents"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4"
android:padding="10dp"
android:visibility="gone"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Cheese"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Tomatos"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Wheat"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Salt"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/llContains2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#000000"
>
</LinearLayout>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Contains2"
android:textSize="20dp"
android:layout_marginLeft="10dp"
android:padding="10dp"
/>
<LinearLayout
android:id="#+id/llContents2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4"
android:padding="10dp"
android:visibility="gone"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Cheese"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Tomatos"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Wheat"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Salt"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
if it helps then let me know.