如何在每个节点上创建消耗布局 [英] how to create expendable layout on each node
问题描述
即时创建和应用程序,它具有THRE节点(说明,内容,营养),这样的形象 http://imgur.com/ TmJT6GI 的时候用户点击任意一个节点将花费,并显示它里面的另外一个画面我怎么会做呢?我会看到有消耗列表视图可用,但类似这样的例子在每个节点上的节目单列表 HTTP ://ranfeng0610.blog.163.com/blog/static/1857082842011727111359969/ 是我骗费到达节点的节点人秀difrent布局用户界面的布局)我怎么让预订购该screenlike每个节点费的ListView?请帮助我ü有任何想法????
1,main.xml中
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
>
< - 禁用系统自带图标的android:groupIndicator =@空 - >
< ExpandableListView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:groupIndicator =@空
机器人:ID =@ + ID / mExpandableListView
/>
< / LinearLayout中>
2,group.xml < XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
< ImageView的
机器人:layout_width =25dip
机器人:layout_height =25dip
机器人:layout_marginTop =10dip
机器人:ID =@ + ID / mImageView
/>
<的TextView
机器人:ID =@ + ID / group_tv
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:paddingLeft =30像素
机器人:paddingBottom会=10px的
机器人:TEXTSIZE =26sp/>
< / LinearLayout中>
3,child.xml< XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=横向
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
< ImageView的
机器人:layout_gravity =center_vertical
机器人:ID =@ + ID / child_iv
机器人:layout_width =70像素
机器人:layout_height =70像素
机器人:paddingLeft =30像素
机器人:paddingTop =2px的
机器人:paddingBottom会=5像素
机器人:SRC =@绘制/图标/>
<的TextView
机器人:layout_gravity =center_vertical
机器人:ID =@ + ID / child_tv
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:paddingLeft =30像素
机器人:paddingTop =10px的
机器人:paddingBottom会=5像素
机器人:TEXTSIZE =30sp/>
< / LinearLayout中>
u能使其在不使用扩展列表,view..u都只是控制你的观点的知名度。
MainActivity
布尔标志;
布尔FLAG2;
的LinearLayout llContains;
的LinearLayout llContents;
的LinearLayout llContains2;
的LinearLayout llContents2;@覆盖
保护无效的onCreate(捆绑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(新OnClickListener(){ @覆盖
公共无效的onClick(视图v)
{
如果(!标志)
{
llContents.setVisibility(View.VISIBLE);
标志=真实的;
}
其他
{
llContents.setVisibility(View.GONE);
标志= FALSE;
} }
}); llContains2.setOnClickListener(新OnClickListener(){ @覆盖
公共无效的onClick(视图v)
{
如果(!FLAG2)
{
llContents2.setVisibility(View.VISIBLE);
FLAG 2 = TRUE;
}
其他
{
llContents2.setVisibility(View.GONE);
FLAG 2 = FALSE;
} }
});
}
activity_main.xml中
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直
> <滚动型
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直
><的LinearLayout
机器人:ID =@ + ID / llContains
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =3DP
机器人:背景=#000000
> < / LinearLayout中> <的TextView
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:文字=包含
机器人:TEXTSIZE =20dp
机器人:layout_marginLeft =10dp
机器人:填充=10dp
/> <的LinearLayout
机器人:ID =@ + ID / llContents
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:weightSum =4
机器人:填充=10dp
机器人:知名度=水涨船高
> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
机器人:layout_weight =1
机器人:比重=中心
> < ImageView的
机器人:SRC =@绘制/ ic_launcher
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
/> <的TextView 机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:文字=奶酪
/> < / LinearLayout中>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
机器人:layout_weight =1
机器人:比重=中心
> < ImageView的
机器人:SRC =@绘制/ ic_launcher
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:layout_weight =1/> <的TextView 机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:文字=蕃茄
/> < / LinearLayout中>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
机器人:layout_weight =1
机器人:比重=中心
>
< ImageView的
机器人:SRC =@绘制/ ic_launcher
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:layout_weight =1/> <的TextView 机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:文字=小麦
/> < / LinearLayout中>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
机器人:layout_weight =1
机器人:比重=中心
>
< ImageView的
机器人:SRC =@绘制/ ic_launcher
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:layout_weight =1/> <的TextView 机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:文字=盐
/> < / LinearLayout中> < / LinearLayout中> < / LinearLayout中> <的LinearLayout
机器人:ID =@ + ID / llContains2
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =3DP
机器人:背景=#000000
> < / LinearLayout中> <的TextView
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:文字=Contains2
机器人:TEXTSIZE =20dp
机器人:layout_marginLeft =10dp
机器人:填充=10dp
/> <的LinearLayout
机器人:ID =@ + ID / llContents2
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:weightSum =4
机器人:填充=10dp
机器人:知名度=水涨船高
> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
机器人:layout_weight =1
机器人:比重=中心
> < ImageView的
机器人:SRC =@绘制/ ic_launcher
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
/> <的TextView 机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:文字=奶酪
/> < / LinearLayout中>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
机器人:layout_weight =1
机器人:比重=中心
> < ImageView的
机器人:SRC =@绘制/ ic_launcher
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:layout_weight =1/> <的TextView 机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:文字=蕃茄
/> < / LinearLayout中>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
机器人:layout_weight =1
机器人:比重=中心
>
< ImageView的
机器人:SRC =@绘制/ ic_launcher
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:layout_weight =1/> <的TextView 机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:文字=小麦
/> < / LinearLayout中>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
机器人:layout_weight =1
机器人:比重=中心
>
< ImageView的
机器人:SRC =@绘制/ ic_launcher
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:layout_weight =1/> <的TextView 机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:文字=盐
/> < / LinearLayout中> < / LinearLayout中> < / LinearLayout中> < / LinearLayout中> < /滚动型>
< / 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.
这篇关于如何在每个节点上创建消耗布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!