好了,请允许我再次问这个问题,因为一切答案在什么我真正感兴趣的(道歉,如果像这样的问题的整体规模的编辑是一个人造PAUS)获得.
几点:
让我们创建一个名为pack的函数,它将一个整数(称为alignment)和一个整数元组(称为元素)作为输入.它输出另一个整数,称为大小.
该功能的工作原理如下:
int pack (int alignment, int[] elements)
{
total_size = 0;
foreach( element in elements )
{
while( total_size % min(alignment, element) != 0 ) { ++total_size; }
total_size += element;
}
while( total_size % packing != 0 ) { ++total_size; }
return total_size;
}
Run Code Online (Sandbox Code Playgroud)
我想我要问的是,但我不知道是否反转是正确的说法"这是什么函数的反函数?" - 我不记得曾经处理的多输入功能倒置,所以我可能只是使用不适用的术语.
像我想要的东西(有点像)存在; 这里我提供了一个我们称之为determine_align的函数的伪代码.但是,这个函数有点幼稚,因为它只是用不同的输入一遍又一遍地调用pack,直到得到它预期的答案(或失败).
int determine_align(int total_size, int[] elements)
{
for(packing = 1,2,4,...,64) // expected answers.
{
size_at_cur_packing = pack(packing, elements);
if(actual_size == size_at_cur_packing)
{
return packing;
}
} …Run Code Online (Sandbox Code Playgroud) 我想在黑莓的底部放一个菜单,菜单项添加到水平字段管理器...如何将菜单放在屏幕的底部...
我目前正在使用以下代码来执行此操作.
<span style="position: absolute; bottom: 0pt; right: 0pt;">
Load time: 1.1920928955078E-5 seconds</span>
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,如果页面是可滚动的,那么它就在页面的中间位置.我确信这有一个简单的解决方案,但我无法想出来.
任何帮助或建议将不胜感激.
我如何对齐文本以便它切割字符串的前140个字符,并用空格填充其余的字符?
例如,"%140s"%some_text但另一边的空间.
思考?
我目前正在从服务器的xml文件中将文本加载到我的应用程序中.但是,这些文本被分配给TextView.根据我的需要,我的文字没有对齐.即我希望那些文本作为微软词的理由.
<TextView android:id="@+id/nvContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:layout_weight="1"
android:gravity="fill"
android:text="Inglot Cosmetics now in Kathmandu Inglot, which has been selling its products in over 240 stores all over the world is now here for you in Kathmandu. It has one of the most extensive colour ranges in cosmetics collections. Working with the best makeup artists, Inglot brings you the latest trends in colour, texture and form. Experiment with countless shades and combinations of face powder, blushers, eye shadows and lipsticks."
android:textColor="#ff000000" …Run Code Online (Sandbox Code Playgroud) 我有这段HTML代码:
<div id="main" style=" margin:0 auto; ">
<div style="float: left">
<a style="display: block" href="#"><img src="test.gif"></a>
<a style="display: block" href="#"><img src="test.gif"></a>
<a style="display: block" href="#"><img src="test.gif"></a>
</div>
<div style="float: left">
<a style="display: block;" href="#"><img src="ursus.gif"></a>
</div>
<div style="float: left">
<a style="display: block" href="#"><img src="test.gif"></a>
<a style="display: block" href="#"><img src="test.gif"></a>
<a style="display: block" href="#"><img src="test.gif"></a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我希望#main div在页面的中心对齐.我这么干嘛?谢谢!
我正在BlackBerry中使用基于UI的应用程序.UI如下所示:
Run Code Online (Sandbox Code Playgroud)label-1 : Oject choice field-1 label-2 : Oject choice field-2 label-3 : Oject choice field-3 label-4 : Oject choice field-4 label-5 : Oject choice field-5
生成此UI实际上变得非常困难.宽度和高度是我遇到困难的主要问题.
public HomeScreen() {
super(MainScreen.USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL);
_dbOperations = new DBOperations();
_mainVFM = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH);
_mainVFM.setMargin(10, 10, 40, 10);
_menuFieldVFM = new VerticalFieldManager();
_menuFieldVFM.setMargin(0, 5, 0, 0);
_menuDropDownVFM = new VerticalFieldManager();
((VerticalFieldManager) getMainManager()).setBackground(BackgroundFactory.createSolidBackground(Constants.BgColorCode));
XYEdges padding = new XYEdges(1, 1, 1, 1);
Border roundedBorder = BorderFactory.createSimpleBorder(padding);
// HEADING
_headingHFM = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);
_headingLabelField …Run Code Online (Sandbox Code Playgroud) 给定一个指向T的指针,我想确定T是否跨越N字节对齐的地址.在实践中我真的只关心0-5字节大小的对象是否跨越8或16字节字节边界,但我写了这个通用版本:
template<class T, unsigned long N>
bool straddlesBoundary(T* obj)
{
unsigned long before = (unsigned long)obj & ~(N-1);
unsigned long after = ((unsigned long)obj + sizeof(T) - 1) & ~(N-1);
return before != after;
}
Run Code Online (Sandbox Code Playgroud)
基本上,将地址向下舍入到最接近的N字节对齐地址,然后将指针增量乘以T的大小减1(因为T在下一个边界上的右边不算作跨骑)并将其向下舍入到最近N字节对齐的地址,如果匹配,则表示它不会跨越.
有更快的方法吗?我刚刚做了这个,我不知道是否有标准检查.
编辑:注意,我假设T小于N.
问题很简单.我有一个主屏幕,北区必须显示两个文本字段和一个按钮,以便用户连接.
我有这个代码.
Ext.create('Ext.container.Viewport', {
layout: 'anchor',
id: 'homescreen',
items: [
{
layout: 'border',
border: false,
height: 160,
anchor: '100%',
items: [
{
region: 'west',
// some codes here
},
{
xtype: 'container',
width: '70%',
region: 'east',
layout:
{
type: 'table',
columns: 1,
tdAttrs:
{
style: 'padding: 5px 15px 5px 15px;',
align: 'middle',
},
defaults:
{
width: 150,
textAlign: 'right'
},
},
items: [
{
xtype: 'textfield',
//fieldLabel: 'login',
labelWidth:50,
emptyText: 'Utilisateur',
margin: '18 0 0 0',
},
{
xtype: 'textfield', …Run Code Online (Sandbox Code Playgroud) 我有一个JTabbedPane标签位置设置为LEFT.问题是每个标签中的图标不是彼此垂直对齐的.
考虑这张图:

正如你所看到的"Editar Protocolo"(第二个选项卡)的图标不完全符合"Distribuir Protocolo"(第一个选项卡)的图标排列,这也与其他标签发生.我希望所有图标都垂直对齐到左边.
这是我用来设置标签组件的代码:
...
jtabbedPane.setTabComponentAt(1, configurarJtabbedPane("Editar Protocolo", iconEditarProtocolo));
...
public JLabel configurarJtabbedPane(String title, ImageIcon icon) {
JLabel l = new JLabel(title);
l.setIcon(icon);
l.setIconTextGap(5);
l.setHorizontalTextPosition(SwingConstants.RIGHT);
return l;
}
Run Code Online (Sandbox Code Playgroud)
代码从标签左侧的 Q&A:JTabbedPane:图标中提取.