当此选项卡是当前选项卡时,我正试图找到能够在选项卡上触发onclick事件的方法.
我确实尝试过这种方式(在其他几种方式中)并没有成功.
public void onTabChanged(String tabId) {
Log.d(this.getClass().getName(), ">>>>>>>>>>>>>>>>>>>>>>>> tabId: " + tabId);
int tabs = getTabWidget().getChildCount();
Log.d(this.getClass().getName(), "tabs: " + tabs);
for(int i=0; i<tabs; i++){
View tab = getTabWidget().getChildAt(i);
if(i==tabHost.getCurrentTab()){
Log.d(this.getClass().getName(), "tab: " + i);
tab.setOnClickListener(this);
}else{
tab.setOnClickListener(null);
tab.getOnFocusChangeListener();
}
}
}
Run Code Online (Sandbox Code Playgroud)
关键是我设置为onClickListener,null所以下次单击选项卡时没有任何反应,但我希望有正常的选项卡行为.
外面有什么想法吗?
我正在尝试实现一个可以同时保存横向或纵向图像的ImageView.这些图像应该适合图像视图的宽度(如果是横向)或高度(如果是肖像),但无论如何它们必须与视图的顶部对齐,没有边距或填充.
我想实现的是一样的东西android:scaleType="fitStart",但集中在人像图像的情况下,或对准景观图像的情况下到上.
添加:
现在我正在使用这样一个丑陋的代码,这似乎有效,但不确定它是最好的解决方案:
<com.custom.layout.MyImageView
android:id="@+id/detail_view_image"
android:src="@drawable/logo"
android:background="#fff"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:cropToPadding="false"
android:adjustViewBounds="false"
/>
Run Code Online (Sandbox Code Playgroud)
然后在我的课上,我扩展了ImageView:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int imgWidth = getDrawable().getIntrinsicWidth();
int imgHeight = getDrawable().getIntrinsicHeight();
if(imgWidth>imgHeight)
setScaleType(ScaleType.FIT_START);
else
setScaleType(ScaleType.FIT_CENTER);
int width = measureWidth(widthMeasureSpec);
int height = measureHeight(heightMeasureSpec);
setMeasuredDimension(width, height);
}
Run Code Online (Sandbox Code Playgroud) 我有一个LinearLayout包含一些其他观点,其中一个ListView.通过单击按钮从另一个视图加载此视图.
此按钮以某种方式指定ListView中的哪个元素需要是列表中第一个可见的元素.填充列表的元素是通过HTTP从外部服务器检索的.
问题是我可以将第N个元素作为列表中的第一个元素.请注意,我不想将其从当前位置移动到新位置,我希望列表滚动.
我曾尝试与setSelected()和scrollTo(x,y)和scrollBy(x,y),但没有运气.
我也尝试过这个代码,虽然它很丑,但我只想尝试f它工作:
ListView categoryList = (ListView)findViewById(R.id.category_list);
categoryList.post(new Runnable() {
@Override
public void run() {
Log.d(this.getClass().getName(), "CategoryActivity.scrollToIndex: " + CategoryActivity.scrollToIndex);
if(CategoryActivity.scrollToIndex>0){
ListView categoryList = (ListView)findViewById(R.id.category_list);
categoryList.setScrollContainer(true);
categoryList.scrollTo(4, CategoryActivity.scrollToIndex * 50);
categoryList.requestLayout();
}
}
});
Run Code Online (Sandbox Code Playgroud)
这给了我一些成功,但ListView当时表现得很疯狂,我甚至无法描述......
任何的想法?