我有两个不嵌套的div,一个在另一个之下.它们都在一个父div中,并且这个父div重复自己.基本上:
<div id='parent_div_1'>
<div class='child_div_1'></div>
<div class='child_div_2'></div>
</div>
<div id='parent_div_2'>
<div class='child_div_1'></div>
<div class='child_div_2'></div>
</div>
<div id='parent_div_3'>
<div class='child_div_1'></div>
<div class='child_div_2'></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想让每一对child_div_1和child_div_2彼此相邻.我怎样才能做到这一点?
我想在布局级别根据实际模板定义进行条件渲染content_for(:an__area),任何想法如何完成?
我有一个res/layout/main.xml包括这些元素和其他:
<some.package.MyCustomView android:id="@+id/foo" (some other params) />
<TextView android:id="@+id/boring" (some other params) />
Run Code Online (Sandbox Code Playgroud)
在我的Activity的onCreate中,我这样做:
setContentView(R.layout.main);
TextView boring = (TextView) findViewById(R.id.boring);
// ...find other elements...
MyCustomView foo = (MyCustomView) findViewById(R.id.foo);
if (foo == null) { Log.d(TAG, "epic fail"); }
Run Code Online (Sandbox Code Playgroud)
其他元素成功找到,但foo返回null.MyCustomView有一个构造函数,MyCustomView(Context c, AttributeSet a)并且Log.d(...)该构造函数的末尾在"史诗失败"之前的logcat中成功出现.
为什么是foonull?
我有几个相同的HTML元素一个接一个:
<span>1</span>
<span>2</span>
<span>3</span>
Run Code Online (Sandbox Code Playgroud)
我正在寻找仅使用CSS在元素之间添加空间的最佳方法
[no space] [1] [space 10px] [2] [space 10px] [3] [no space]
Run Code Online (Sandbox Code Playgroud)
另外:
UPDATE
看起来我不清楚.我不想使用任何其他HTML MARKUP
<span></span> <span></span> <span class="last_span"></span>
Run Code Online (Sandbox Code Playgroud)
我不想使用表格
我想要CSS自动定位第一个和最后一个跨度
我不想使用javascript
可选要求:最后一个span可以是父标记的最后一个CHILD,但它将是父标记的最后一个SPAN.Spans之间没有任何其他标签.
我想在一个下面显示一个按钮ListView.问题是,如果ListView扩展(添加了项目......),按钮将被推出屏幕.
我尝试了一个LinearLayout带权重(如Android所示:为什么没有一个视图的maxHeight?),但要么我的权重错了,要么根本不起作用.
另外,我发现某处使用了一个提示RelativeLayout.在ListView随后将被与按钮上方设置android:layout_abovePARAM.
问题是我不知道如何在按钮后放置按钮.在我发现的示例中,使用下面的视图ListView进行了调整android:layout_alignParentBottom,但我不希望我的按钮粘在屏幕的底部.
除了使用setHeight方法和一些计算所需空间之外的任何想法?
编辑: 我得到了很多有用的答案.
bigstone的用户和用户639183的解决方案几乎完美无缺.但是,我不得不在按钮的底部添加额外的填充/边距,因为它仍然会被推出屏幕的一半(但随后停止)
如果您希望按钮固定在屏幕底部,Adinia对相对布局的回答很好.这不是我的意图,但仍可能对其他人有用.
AngeloS的解决方案是我最后选择的解决方案,因为它创造了我想要的效果.但是,我LinearLayout对按钮周围做了两处小改动:
首先,因为我不希望在我的布局任何绝对值,我换android:layout_height="45px"到wrap_content,其工作也很不错.
其次,因为我希望按钮水平居中,只有垂直支持LinearLayout,我将android:orientation ="horizontal"改为"vertical".
AngeloS在他的帖子中也说过,他不确定周围的android:layout_weight="0.1"参数是否有任何影响; 我刚试过,它确实做到了!没有,按钮再次被推出屏幕.LinearLayoutListView
我正在遵循如何添加a的标准示例RatingBar.控制我试图使用的星星数量android:numStars="5".问题是星星的数量似乎根本不起作用.在纵向布局中,我获得了6颗星,当我翻动手机时,我得到了大约10颗星.我试图在我的Activity(myBar.setNumStars(5))中设置加载xml 的星数,但是该选项也没有成功.
所以我的问题是如何定义我的布局,以便它只显示五颗星?设置numStars似乎不起作用.
罗兰,提前谢谢
在Android的设计指南说,使用无边框按钮(见下图),但真的不解释如何.几个星期前有人问过同样的问题:如何创建标准的无边框按钮(如提到的设计指南)?并且有一个答案标记为"答案",但我仍然迷失了,我没有办法在一个已经"关闭"的问题上添加评论
答案者说
"看入主题属性
buttonBarStyle,buttonBarButtonStyle以及borderlessButtonStyle"
但我仍然无法弄清楚如何实际使用这些东西.我用Google搜索了一下,找不到任何东西,所以我想我只是再问这个问题,希望有人可以提供一些更详细的信息.

每当我开始这项活动时,它总是从最低点开始 - 一直向下滚动到底部.我没有在活动OnCreate(或其他任何地方)做任何奇怪的事情,我希望改变滚动位置.我已经尝试将焦点设置到最顶层的可聚焦控件和scrollto方法,但它们都没有工作.此外,我的其他活动都没有这个问题.这是布局:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit_refresh_update_header"
android:textSize="18sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="\n"
android:textSize="4sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Variable:"
android:textSize="18sp"/>
<Spinner
android:id="@+id/edit_refresh_variables_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="\n"
android:textSize="4sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Network:"
android:textSize="18sp"/>
<RadioGroup
android:id="@+id/widget1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<RadioButton
android:text="Web"
android:id="@+id/edit_refresh_update_rb_web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="NetRadioButtonSelected"
android:checked="true"/>
<RadioButton
android:text="Socket Server"
android:id="@+id/edit_refresh_update_rb_socket_server"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="NetRadioButtonSelected"/>
</RadioGroup>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="\n"
android:textSize="4sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Socket server request type:"
android:textSize="18sp"/>
<Spinner
android:id="@+id/edit_refresh_socket_server_req_types_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView …Run Code Online (Sandbox Code Playgroud) 这似乎应该很容易,但我只是没有得到什么.
我想创建一个包含单个SVG图像的HTML页面,该图像会自动缩放以适应浏览器窗口,无需任何滚动,同时保留其纵横比.
例如,目前我有一个1024x768的SVG图像; 如果浏览器视口是1980x1000,那么我希望图像显示为1333x1000(垂直填充,水平居中).如果浏览器是800x1000,那么我希望它以800x600显示(水平填充,垂直居中).
目前我的定义如下:
<body style="height: 100%">
<div id="content" style="width: 100%; height: 100%">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
width="100%" height="100%"
viewBox="0 0 1024 768"
preserveAspectRatio="xMidYMid meet">
...
</svg>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
然而,这是扩展到浏览器的整个宽度(对于宽而短的窗口)并产生垂直滚动,这不是我想要的.
我错过了什么?