我只有一个活动是ListActivity.基本上我使用以下代码剪切来"激活"CAB:
ListView listView = getListView();
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position,
long id, boolean checked) {
// Here you can do something when items are selected/de-selected,
// such as update the title in the CAB
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Respond to clicks on the actions in the CAB
switch (item.getItemId()) {
case R.id.menu_delete:
deleteSelectedItems();
mode.finish(); // Action picked, so close the CAB
return true; …Run Code Online (Sandbox Code Playgroud) android android-layout android-listview android-linearlayout
我有一个垂直,设置高度(300px)LinearLayout(LL)与3嵌套LL.1和3设置为android:layout_height ="wrap_content",中间设置为android:layout_height ="fill_parent".令我沮丧的是,第3个LL被推出第二个填充父布局直到底部.我如何达到预期的效果,因为我希望可能调整外部容器的大小,中间部分扩展和收缩以适应变化
将线性布局的两个或多个元素设置为相同的高度似乎是一个很大的问题.
我想将一行中的四个按钮设置为相同的高度.
android:layout_height ="wrap_content"暂时执行,但当其中一个按钮上的文本长于一行时,此按钮会增加,因此比其他按钮大.由于不同的本地化我不知道,何时以及哪个按钮可能有第二行.
所以我的想法是,将parent linearlayout设置为android:layout_height ="wrap_content"和所有(!)子高度到android:layout_height ="fill_parent".
这是有效的(所有按钮都有相同的大小),但我不确定这是否会导致任何其他问题?因为父母从孩子那里得到它的高度,反之亦然.
好的,我有两个线性布局按钮:
<LinearLayout android:id="@+id/linearLayout1"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button android:id="@+id/aktiviraj_paket"
android:text="Aktiviraj"
android:layout_height="40sp"
android:layout_width="160sp"
android:background="@drawable/my_border3"
android:onClick="myClickHandle"></Button>
<Button android:id="@+id/deaktiviraj_paket"
android:text="Deaktiviraj"
android:layout_height="40sp"
android:layout_width="fill_parent"
android:background="@drawable/my_border3"
android:onClick="myClickHandle">
</Button>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
所以问题是,如果我在两个按钮上使用填充父项,它们是一个在一起,所以我已经制作了第一个按钮160sp宽度,第二个是fill_parent.如果这个显示在4英寸或更小的屏幕上,按钮大小相同,但如果我在平板电脑上尝试这个(10英寸),第一个按钮保持160sp宽,第二个按钮延伸到屏幕结束(因为fill_parent).我可以做到这一点,所以无论屏幕尺寸大小,两个按钮都可以是均匀尺寸吗?
我的布局包含一些文本字段,并且背景图像显示在我的活动顶部.我希望背景图像可以缩放以包装内容(不关心宽高比).但是,图像大于内容,因此布局反而包裹背景图像.这是我的原始代码:
<RelativeLayout
android:layout_width="fill_parent"
android:id="@+id/HeaderList"
android:layout_gravity="top"
android:layout_height="wrap_content"
android:background="@drawable/header">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/NameText"
android:text="Jhn Doe"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingLeft="4dp"
android:paddingTop="4dp"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#FFFFFF"
android:layout_alignParentLeft="true"
android:id="@+id/HoursText"
android:text="170 hours"
android:textSize="23sp"
android:layout_below="@+id/NameText"
android:paddingLeft="4dp"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
在搜索了其他一些问题后,我发现了这两个问题:
基于此,我创建了一个带有ImageView的FrameLayout,显示背景.不幸的是,我仍然无法让它工作.我想要的背景图像的高度缩小/扩大W /文观点的大小,但与FrameLayout里,该ImageView的适合的大小的它的父,我无法找到一个办法让母公司适合文本视图布局的大小.这是我更新的代码:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView android:src="@drawable/header"
android:layout_width="fill_parent"
android:scaleType="fitXY"
android:layout_height="fill_parent"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:id="@+id/HeaderList"
android:layout_gravity="top"
android:layout_height="wrap_content"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/NameText"
android:text="John Doe"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingLeft="4dp"
android:paddingTop="4dp"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#FFFFFF"
android:layout_alignParentLeft="true"
android:id="@+id/HoursText"
android:text="170 hours"
android:textSize="23sp"
android:layout_below="@+id/NameText"
android:paddingLeft="4dp"
/>
</RelativeLayout> …Run Code Online (Sandbox Code Playgroud) android background android-linearlayout android-relativelayout android-framelayout
我想将背景设置android.R.attr.selectableItemBackground为a LinearLayout.使用XML时没有问题(可行)
<LinearLayout
android:id="@+id/llMiner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:clickable="true" >
Run Code Online (Sandbox Code Playgroud)
...但我必须在java代码中这样做,所以我试过这个
llMiner.setClickable(true);
llMiner.setBackgroundResource(android.R.attr.selectableItemBackground);
Run Code Online (Sandbox Code Playgroud)
......它不起作用,事实上我得到了NotFoundException第二行.所以在我尝试了这个变体后认为资源是一个颜色.
llMiner.setClickable(true);
llMiner.setBackgroundColor(android.R.attr.selectableItemBackground);
Run Code Online (Sandbox Code Playgroud)
这个没有启动异常,但是......不起作用(按下时没有改变背景,但是状态改变按下它必须这样做)...任何建议?
我有以下布局我想让textview出现在视图的中心和中间.我怎么能做到这一点?
我在图形视图中查看布局时尝试调整各种重力属性,但似乎没有任何改变它.我想在中心的textview我已经完成但是在视图的中间.
谢谢亚光.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/carefreebgscaledalphajpg" >
<TextView
android:id="@+id/textviewdatefornocallspage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="You have no calls for "
android:textSize="25sp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我完全被这个困扰了.我有三个不同的列表需要在屏幕上显示.列表完全可能会延伸到屏幕的下边缘,所以我需要滚动.
我已经尝试过ScrollView和一个LinearLayout孩子一起使用,然后把我ListViews的LinearView所有ListViews锁都用滚动条固定在一个固定的高度上.使用其他类型的布局意味着不滚动.
有没有人有任何建议,或者我是否需要以编程方式将列表项添加到某些布局并希望最好?
我正在创建一个基于聊天的UI屏幕,其中我有聊天消息的工具栏和recyclerview,并回复msg布局.
每当edittext获得焦点时它会向上移动工具栏.相反,我想重新调整recyclerview的大小.
一些stackoverflow答案建议在工具栏下方放置一个空的滚动视图,但它不起作用.
<activity
android:name=".PostMessageActivity"
android:label="@string/title_activity_post_message"
android:windowSoftInputMode="stateVisible|adjustResize"
>
</activity>
Run Code Online (Sandbox Code Playgroud)
我设置windowSoftInputMode到stateVisible|adjustPan清单文件.
<RelativeLayout 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"
tools:context="com.pasonet.yokibu.PostMessageActivity"
>
<include
android:id="@+id/toolbar_home"
layout="@layout/toolbar_home"
android:elevation="5dp"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar_home"
android:orientation="vertical"
android:layout_above="@+id/add_post_layout"
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/post_msg_recyclerview"
>
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:padding="5dp"
android:id="@+id/add_post_layout"
android:background="#ffffff"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:elevation="5dp"
android:layout_margin="0pt"
>
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/messageText"
android:layout_gravity="bottom"
android:layout_weight="1"
android:maxLines="4"
android:scrollbars="vertical"
android:background="@color/trasnperant"
android:hint="Type your message"
android:layout_marginBottom="4dp"
/>
<ImageButton
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) android android-appcompat android-linearlayout android-toolbar android-recyclerview
我在一个帧布局中有两个线性布局.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left"
android:orientation="vertical">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/image12">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/layoutbtnlinear_aboutme"
android:layout_width="fill_parent"
android:layout_height="55dp"
android:gravity="bottom"
android:layout_marginTop="10dp"
android:background="#b2b2b2"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imgShare_layout_aboutme"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_gravity="right|center|end"
android:layout_weight="1.63"
android:src="@drawable/ic_share" />
<TextView
android:id="@+id/txtTitle_layout_aboutme"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_gravity="left"
android:layout_weight="0.3"
android:fontFamily="Times New Roman"
android:text="About Me"
android:textColor="@android:color/black"
android:textSize="35sp"
android:textStyle="italic" />
</LinearLayout>
<LinearLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageButton
android:id="@+id/btnSlidingDrawerHandler_layout_aboutme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ic_1_navigation_collapse" />
<ListView
android:id="@+id/listView_layout_aboutme"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:footerDividersEnabled="true"
android:dividerHeight="4px"
android:isScrollContainer="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideInset"
android:scrollbars="vertical">
</ListView>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在这里,我设置top margin了ID layoutbtnlinear_aboutme …
android ×10
background ×2
button ×1
clickable ×1
listview ×1
position ×1
scrollview ×1
view ×1
xml ×1