这是我的布局。我的问题是,其中的列表视图不会增加项目数的高度。 当我使用wrap_content给定高度(如210像素)时,它会显示数据...当我将高度设置为wrap_content时,它只显示一个项目。
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/rl_createPro_option"
android:orientation="vertical"
android:layout_marginTop="5dp"
android:visibility="gone"
android:layout_marginBottom="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Please provide option-wise price:"/>
<ListView
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:id="@+id/rv_createPro"
android:layout_height="wrap_content" />
<RadioGroup
android:layout_width="match_parent"
android:id="@+id/rg_createPro"
android:layout_marginTop="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Option highlight??"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="yes"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="no"/>
</RadioGroup>
</LinearLayout>
请帮助我!!
答案 0 :(得分:1)
这是因为您使用vertical
方向进行线性布局,因此保留views
radioGroups
下方public static void setListViewHeightBasedOnChildren(final ListView listView) {
listView.post(new Runnable() {
@Override
public void run() {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
return;
}
int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();
int listWidth = listView.getMeasuredWidth();
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(
View.MeasureSpec.makeMeasureSpec(listWidth, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
totalHeight += listItem.getMeasuredHeight();
Log.d("listItemHeight " + listItem.getMeasuredHeight(), "********");
}
Log.d("totalHeight " + totalHeight, "********");
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = (totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)));
listView.setLayoutParams(params);
listView.requestLayout();
}
});
}
的空间。列表视图的设置高度动态使用
org.openqa.selenium.WebDriverException: {"errorMessage":"Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: \"script-src 'report-sample' 'sha256-6gLjSWp3GRKZCUFvRX5aGHtECD1wVRgJOJp7r0ZQjV0=' 'unsafe-inline' static.licdn.com s.c.lnkd.licdn.com static-fstl.licdn.com static-src.linkedin.com https://www.linkedin.com/voyager/service-worker-push.js https://platform.linkedin.com/js/analytics.js static-exp1.licdn.com static-exp2.licdn.com s.c.exp1.licdn.com s.c.exp2.licdn.com static-lcdn.licdn.com s.c.lcdn.licdn.com https://www.linkedin.com/sc/ https://www.linkedin.com/scds/ https://qprod.www.linkedin.com/sc/ https://www.linkedin.com/sw.js https://www.linkedin.com/voyager/abp-detection.js\".\n","request":{"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"291","Content-Type":"application/json; charset=utf-8","Host":"localhost:14248","User-Agent":"Apache-HttpClient/4.5.3 (Java/1.8.0_60)"},"httpVersion":"1.1","method":"POST","post":"{\"script\":\"var x=document.getElementsByClassName(\\\"mentions-texteditor__contenteditable\\\");x[0].innerHTML=\\\"<p>That's far more painful than a record-keeping God up in the skies.<br></p>\\\";\",\"args\":[{\"ELEMENT\":\":wdc:1515140075880\",\"element-6066-11e4-a52e-4f735466cecf\":\":wdc:1515140075880\"}]}","url":"/execute","urlParsed":{"anchor":"","query":"","file":"execute","directory":"/","path":"/execute","relative":"/execute","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/execute","queryKey":{},"chunks":["execute"]},"urlOriginal":"/session/6160fa40-f1f0-11e7-9786-bb95dc5c4adc/execute"}}
Command duration or timeout: 1.96 seconds
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:573)
at com.gaodig.linkedin.LinkedInOps.shareSth(LinkedInOps.java:125)
at com.gaodig.linkedin.LinkedInOps.main(LinkedInOps.java:219)
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:141)
... 4 more
Caused by: org.openqa.selenium.WebDriverException: {"errorMessage":"Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: \"script-src 'report-sample' 'sha256-6gLjSWp3GRKZCUFvRX5aGHtECD1wVRgJOJp7r0ZQjV0=' 'unsafe-inline' static.licdn.com s.c.lnkd.licdn.com static-fstl.licdn.com static-src.linkedin.com https://www.linkedin.com/voyager/service-worker-push.js https://platform.linkedin.com/js/analytics.js static-exp1.licdn.com static-exp2.licdn.com s.c.exp1.licdn.com s.c.exp2.licdn.com static-lcdn.licdn.com s.c.lcdn.licdn.com https://www.linkedin.com/sc/ https://www.linkedin.com/scds/ https://qprod.www.linkedin.com/sc/ https://www.linkedin.com/sw.js https://www.linkedin.com/voyager/abp-detection.js\".\n","request":{"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"291","Content-Type":"application/json; charset=utf-8","Host":"localhost:14248","User-Agent":"Apache-HttpClient/4.5.3 (Java/1.8.0_60)"},"httpVersion":"1.1","method":"POST","post":"{\"script\":\"var x=document.getElementsByClassName(\\\"mentions-texteditor__contenteditable\\\");x[0].innerHTML=\\\"<p>That's far more painful than a record-keeping God up in the skies.<br></p>\\\";\",\"args\":[{\"ELEMENT\":\":wdc:1515140075880\",\"element-6066-11e4-a52e-4f735466cecf\":\":wdc:1515140075880\"}]}","url":"/execute","urlParsed":{"anchor":"","query":"","file":"execute","directory":"/","path":"/execute","relative":"/execute","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/execute","queryKey":{},"chunks":["execute"]},"urlOriginal":"/session/6160fa40-f1f0-11e7-9786-bb95dc5c4adc/execute"}}
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'MS-20161025GMIQ', ip: '10.76.124.130', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_60'
Driver info: driver.version: unknown